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
@@ -49,7 +49,7 @@ namespace PrivaPub.Services
|
||||
{
|
||||
var author = await OwnedAvatar(rootUserId, form.AvatarId, token);
|
||||
if (author == default)
|
||||
return new WebResult().Invalidate(localizer["Avatar not found."], StatusCodes.Status404NotFound);
|
||||
return new WebResult().Invalidate(29001.ToCodedError(localizer["Avatar not found."]), StatusCodes.Status404NotFound);
|
||||
return await Answer(() => statuses.Publish(author, new StatusDraft
|
||||
{
|
||||
Text = form.Text,
|
||||
@@ -69,7 +69,7 @@ namespace PrivaPub.Services
|
||||
{
|
||||
var author = await OwnedAvatar(rootUserId, form.AvatarId, token);
|
||||
if (author == default)
|
||||
return new WebResult().Invalidate(localizer["Avatar not found."], StatusCodes.Status404NotFound);
|
||||
return new WebResult().Invalidate(29002.ToCodedError(localizer["Avatar not found."]), StatusCodes.Status404NotFound);
|
||||
var result = await Answer(() => statuses.Remove(author, form.PostId, token), nameof(DeletePost), token);
|
||||
result.Data = default;
|
||||
return result;
|
||||
@@ -79,7 +79,7 @@ namespace PrivaPub.Services
|
||||
{
|
||||
var author = await OwnedAvatar(rootUserId, form.AvatarId, token);
|
||||
if (author == default)
|
||||
return new WebResult().Invalidate(localizer["Avatar not found."], StatusCodes.Status404NotFound);
|
||||
return new WebResult().Invalidate(29003.ToCodedError(localizer["Avatar not found."]), StatusCodes.Status404NotFound);
|
||||
return await Answer(() => statuses.Edit(author, form.PostId, new StatusDraft
|
||||
{
|
||||
Text = form.Text,
|
||||
@@ -96,7 +96,7 @@ namespace PrivaPub.Services
|
||||
{
|
||||
var avatar = await OwnedAvatar(rootUserId, avatarId, token);
|
||||
if (avatar == default)
|
||||
return result.Invalidate(localizer["Avatar not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(29004.ToCodedError(localizer["Avatar not found."]), StatusCodes.Status404NotFound);
|
||||
|
||||
var query = dbEntities.Posts;
|
||||
if (string.IsNullOrEmpty(groupId))
|
||||
@@ -107,7 +107,7 @@ namespace PrivaPub.Services
|
||||
.Match(g => g.ID == groupId && g.Members.Any(m => !m.IsForeign && m.AvatarId == avatar.Id))
|
||||
.ExecuteAnyAsync(token);
|
||||
if (!isMember)
|
||||
return result.Invalidate(localizer["Group not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(29005.ToCodedError(localizer["Group not found."]), StatusCodes.Status404NotFound);
|
||||
query.Match(p => p.GroupId == groupId);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace PrivaPub.Services
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"{nameof(PostsService)}.{nameof(GetPosts)}");
|
||||
return result.Invalidate(localizer["Something went wrong."], exception: ex);
|
||||
return result.Invalidate(29006.ToCodedError(localizer["Something went wrong."]), exception: ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,9 +126,9 @@ namespace PrivaPub.Services
|
||||
{
|
||||
var author = await OwnedAvatar(rootUserId, form.AvatarId, token);
|
||||
if (author == default)
|
||||
return new WebResult().Invalidate(localizer["Avatar not found."], StatusCodes.Status404NotFound);
|
||||
return new WebResult().Invalidate(29007.ToCodedError(localizer["Avatar not found."]), StatusCodes.Status404NotFound);
|
||||
if (string.IsNullOrEmpty(form.DmGroupId) && form.Recipients.Count == 0)
|
||||
return new WebResult().Invalidate(localizer["At least one recipient is required."]);
|
||||
return new WebResult().Invalidate(29008.ToCodedError(localizer["At least one recipient is required."]));
|
||||
return await Answer(() => statuses.Publish(author, new StatusDraft
|
||||
{
|
||||
Text = form.Text,
|
||||
@@ -146,7 +146,7 @@ namespace PrivaPub.Services
|
||||
{
|
||||
var avatar = await OwnedAvatar(rootUserId, avatarId, token);
|
||||
if (avatar == default)
|
||||
return result.Invalidate(localizer["Avatar not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(29009.ToCodedError(localizer["Avatar not found."]), StatusCodes.Status404NotFound);
|
||||
|
||||
if (string.IsNullOrEmpty(dmGroupId))
|
||||
{
|
||||
@@ -167,7 +167,7 @@ namespace PrivaPub.Services
|
||||
.Match(g => g.ID == dmGroupId && g.Members.Any(m => !m.IsForeign && m.AvatarId == avatar.Id))
|
||||
.ExecuteAnyAsync(token);
|
||||
if (!isMember)
|
||||
return result.Invalidate(localizer["Conversation not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(29010.ToCodedError(localizer["Conversation not found."]), StatusCodes.Status404NotFound);
|
||||
|
||||
var dms = await dbEntities.Posts
|
||||
.Match(p => p.ConversationId == dmGroupId && p.Visibility == PostVisibility.Direct)
|
||||
@@ -181,7 +181,7 @@ namespace PrivaPub.Services
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"{nameof(PostsService)}.{nameof(GetDms)}");
|
||||
return result.Invalidate(localizer["Something went wrong."], exception: ex);
|
||||
return result.Invalidate(29011.ToCodedError(localizer["Something went wrong."]), exception: ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,9 +192,9 @@ namespace PrivaPub.Services
|
||||
var result = new WebResult();
|
||||
var viewer = await OwnedAvatar(rootUserId, avatarId, token);
|
||||
if (viewer == default)
|
||||
return result.Invalidate(localizer["Avatar not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(29012.ToCodedError(localizer["Avatar not found."]), StatusCodes.Status404NotFound);
|
||||
if (latitude is < -90 or > 90 || longitude is < -180 or > 180)
|
||||
return result.Invalidate(localizer["Invalid model."]);
|
||||
return result.Invalidate(29013.ToCodedError(localizer["Invalid model."]));
|
||||
|
||||
var query = new MongoDB.Bson.BsonDocument
|
||||
{
|
||||
@@ -223,14 +223,14 @@ namespace PrivaPub.Services
|
||||
{
|
||||
var outcome = await action();
|
||||
if (!outcome.Ok)
|
||||
return result.Invalidate(localizer[outcome.Error], outcome.Status);
|
||||
return result.Invalidate(29014.ToCodedError(localizer[outcome.Error]), outcome.Status);
|
||||
result.Data = ToView(outcome.Post);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "{Service}.{Operation}", nameof(PostsService), operation);
|
||||
return result.Invalidate(localizer["Something went wrong."], exception: ex);
|
||||
return result.Invalidate(29015.ToCodedError(localizer["Something went wrong."]), exception: ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user