Every failure the server answers with names its own error code
Each refusal and failure the client API sends now starts with a code no other failure uses, such as "[ERR0030006] That code is not valid.", so a screenshot or a report points at the exact place it came from. Nothing another program reads changes: ActivityPub, the Mastodon API's errors, sign-in tokens and the error kinds decePubClient branches on stay as they were. The house-rules checks move to 1.1.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W4YtEJrgxG12Pc39Fai8Bd
This commit is contained in:
1 parent
f3fdeaf038
commit
c2f439d1e9
25 files changed
+268
-224
No files matched your search
@@ -35,13 +35,13 @@ namespace PrivaPub.Services.ClientToServer.Private
|
||||
{
|
||||
var userName = form.UserName?.Trim().ToLowerInvariant();
|
||||
if (string.IsNullOrEmpty(userName) || !userName.All(c => char.IsAsciiLetterOrDigit(c) || c == '_'))
|
||||
return result.Invalidate(localizer["The username may contain only letters, digits and underscores."]);
|
||||
return result.Invalidate(26001.ToCodedError(localizer["The username may contain only letters, digits and underscores."]));
|
||||
|
||||
if (await localActors.IsUserNameTaken(userName, default))
|
||||
return result.Invalidate(localizer["The username '{0}' is already taken.", userName]);
|
||||
return result.Invalidate(26002.ToCodedError(localizer["The username '{0}' is already taken.", userName]));
|
||||
|
||||
if (!await IsValidRootUser(form.RootId, token))
|
||||
return result.Invalidate(localizer["You can't do this action because of your account status."]);
|
||||
return result.Invalidate(26003.ToCodedError(localizer["You can't do this action because of your account status."]));
|
||||
|
||||
var (privateKey, publicKey) = Keys.NewKeyPair();
|
||||
var newAvatar = new Avatar
|
||||
@@ -59,7 +59,7 @@ namespace PrivaPub.Services.ClientToServer.Private
|
||||
newAvatar.Emojis = PrivaPub.Domain.Content.LocalEmojis.OfProfile(newAvatar);
|
||||
newAvatar.ID = (string)newAvatar.GenerateNewID();
|
||||
if (!await localActors.TryReserveUserName(userName, LocalActorKind.Person, newAvatar.ID, default))
|
||||
return result.Invalidate(localizer["The username '{0}' is already taken.", userName]);
|
||||
return result.Invalidate(26004.ToCodedError(localizer["The username '{0}' is already taken.", userName]));
|
||||
if (form.Settings is { IsDefault: false })
|
||||
Apply(newAvatar.Settings, form.Settings);
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace PrivaPub.Services.ClientToServer.Private
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"{nameof(PrivateAvatarUsersService)}.{nameof(InsertAvatar)}");
|
||||
return result.Invalidate(localizer["Something went wrong."], exception: ex);
|
||||
return result.Invalidate(26005.ToCodedError(localizer["Something went wrong."]), exception: ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,20 +87,20 @@ namespace PrivaPub.Services.ClientToServer.Private
|
||||
try
|
||||
{
|
||||
if (!await IsValidRootUser(form.RootId, token))
|
||||
return result.Invalidate(localizer["You can't do this action because of your account status."]);
|
||||
return result.Invalidate(26006.ToCodedError(localizer["You can't do this action because of your account status."]));
|
||||
|
||||
var owns = await dbEntities.RootToAvatars
|
||||
.Match(ra => ra.RootId == form.RootId && ra.AvatarId == form.AvatarId)
|
||||
.ExecuteAnyAsync(token);
|
||||
if (!owns)
|
||||
return result.Invalidate(localizer["Avatar not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(26007.ToCodedError(localizer["Avatar not found."]), StatusCodes.Status404NotFound);
|
||||
|
||||
var avatar = await dbEntities.Avatars.MatchID(form.AvatarId).ExecuteFirstAsync(token);
|
||||
if (avatar == default || avatar.DeletionAt.HasValue)
|
||||
return result.Invalidate(localizer["Avatar not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(26008.ToCodedError(localizer["Avatar not found."]), StatusCodes.Status404NotFound);
|
||||
// a suspended persona's actor stays as it was until the suspension is lifted (R6)
|
||||
if (avatar.SuspendedAt.HasValue)
|
||||
return result.Invalidate(localizer["This persona is suspended."], StatusCodes.Status403Forbidden);
|
||||
return result.Invalidate(26009.ToCodedError(localizer["This persona is suspended."]), StatusCodes.Status403Forbidden);
|
||||
|
||||
avatar.Name = form.Name;
|
||||
avatar.Biography = form.Biography;
|
||||
@@ -119,7 +119,7 @@ namespace PrivaPub.Services.ClientToServer.Private
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"{nameof(PrivateAvatarUsersService)}.{nameof(UpdateAvatar)}");
|
||||
return result.Invalidate(localizer["Something went wrong."], exception: ex);
|
||||
return result.Invalidate(26010.ToCodedError(localizer["Something went wrong."]), exception: ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ namespace PrivaPub.Services.ClientToServer.Private
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"{nameof(PrivateAvatarUsersService)}.{nameof(GetRootAvatars)}");
|
||||
return result.Invalidate(localizer["Something went wrong."], exception: ex);
|
||||
return result.Invalidate(26011.ToCodedError(localizer["Something went wrong."]), exception: ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user