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
@@ -45,7 +45,7 @@ namespace PrivaPub.Services
|
||||
try
|
||||
{
|
||||
if (!await OwnsAvatar(rootUserId, avatarId, token))
|
||||
return result.Invalidate(localizer["Avatar not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(27001.ToCodedError(localizer["Avatar not found."]), StatusCodes.Status404NotFound);
|
||||
|
||||
var groups = await dbEntities.Groups
|
||||
.Match(g => !g.DeletionAt.HasValue && g.Members.Any(m => !m.IsForeign && m.AvatarId == avatarId))
|
||||
@@ -56,7 +56,7 @@ namespace PrivaPub.Services
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"{nameof(GroupUsersService)}.{nameof(GetGroups)}");
|
||||
return result.Invalidate(localizer["Something went wrong."], exception: ex);
|
||||
return result.Invalidate(27002.ToCodedError(localizer["Something went wrong."]), exception: ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,11 +66,11 @@ namespace PrivaPub.Services
|
||||
try
|
||||
{
|
||||
if (!await OwnsAvatar(rootUserId, form.AvatarId, token))
|
||||
return result.Invalidate(localizer["Avatar not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(27003.ToCodedError(localizer["Avatar not found."]), StatusCodes.Status404NotFound);
|
||||
|
||||
var userName = form.UserName.ToLowerInvariant();
|
||||
if (await localActors.IsUserNameTaken(userName, token))
|
||||
return result.Invalidate(localizer["The username '{0}' is already taken.", userName]);
|
||||
return result.Invalidate(27004.ToCodedError(localizer["The username '{0}' is already taken.", userName]));
|
||||
|
||||
var (privateKey, publicKey) = Keys.NewKeyPair();
|
||||
var group = new GroupEntity
|
||||
@@ -92,7 +92,7 @@ namespace PrivaPub.Services
|
||||
};
|
||||
group.ID = (string)group.GenerateNewID();
|
||||
if (!await localActors.TryReserveUserName(userName, LocalActorKind.Group, group.ID, token))
|
||||
return result.Invalidate(localizer["The username '{0}' is already taken.", userName]);
|
||||
return result.Invalidate(27005.ToCodedError(localizer["The username '{0}' is already taken.", userName]));
|
||||
var actor = localActors.FromGroup(group);
|
||||
group.Url = actor.Uri;
|
||||
group.InboxURL = actor.Inbox;
|
||||
@@ -105,7 +105,7 @@ namespace PrivaPub.Services
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"{nameof(GroupUsersService)}.{nameof(InsertGroup)}");
|
||||
return result.Invalidate(localizer["Something went wrong."], exception: ex);
|
||||
return result.Invalidate(27006.ToCodedError(localizer["Something went wrong."]), exception: ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace PrivaPub.Services
|
||||
{
|
||||
var group = await ManagedGroup(rootUserId, form.AvatarId, form.GroupId, token);
|
||||
if (group == default)
|
||||
return result.Invalidate(localizer["Group not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(27007.ToCodedError(localizer["Group not found."]), StatusCodes.Status404NotFound);
|
||||
|
||||
if (form.Name != default)
|
||||
group.Name = form.Name;
|
||||
@@ -143,7 +143,7 @@ namespace PrivaPub.Services
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"{nameof(GroupUsersService)}.{nameof(UpdateGroup)}");
|
||||
return result.Invalidate(localizer["Something went wrong."], exception: ex);
|
||||
return result.Invalidate(27008.ToCodedError(localizer["Something went wrong."]), exception: ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,13 +153,13 @@ namespace PrivaPub.Services
|
||||
try
|
||||
{
|
||||
if (!await OwnsAvatar(rootUserId, form.AvatarId, token))
|
||||
return result.Invalidate(localizer["Avatar not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(27009.ToCodedError(localizer["Avatar not found."]), StatusCodes.Status404NotFound);
|
||||
|
||||
var group = await dbEntities.Groups
|
||||
.Match(g => g.InvitationCode == form.InvitationCode && !g.DeletionAt.HasValue)
|
||||
.ExecuteFirstAsync(token);
|
||||
if (group == default)
|
||||
return result.Invalidate(localizer["Invalid invitation."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(27010.ToCodedError(localizer["Invalid invitation."]), StatusCodes.Status404NotFound);
|
||||
|
||||
if (!string.IsNullOrEmpty(group.HashedInvitationPassword))
|
||||
{
|
||||
@@ -167,7 +167,7 @@ namespace PrivaPub.Services
|
||||
? (false, false)
|
||||
: passwordHasher.Check(group.HashedInvitationPassword, form.InvitationPassword);
|
||||
if (!verified)
|
||||
return result.Invalidate(localizer["Invalid password."], StatusCodes.Status406NotAcceptable);
|
||||
return result.Invalidate(27011.ToCodedError(localizer["Invalid password."]), StatusCodes.Status406NotAcceptable);
|
||||
}
|
||||
|
||||
if (!group.Members.Any(m => !m.IsForeign && m.AvatarId == form.AvatarId))
|
||||
@@ -184,7 +184,7 @@ namespace PrivaPub.Services
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"{nameof(GroupUsersService)}.{nameof(JoinGroup)}");
|
||||
return result.Invalidate(localizer["Something went wrong."], exception: ex);
|
||||
return result.Invalidate(27012.ToCodedError(localizer["Something went wrong."]), exception: ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,13 +221,13 @@ namespace PrivaPub.Services
|
||||
try
|
||||
{
|
||||
if (!await OwnsAvatar(rootUserId, form.AvatarId, token))
|
||||
return result.Invalidate(localizer["Avatar not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(27013.ToCodedError(localizer["Avatar not found."]), StatusCodes.Status404NotFound);
|
||||
|
||||
var group = await dbEntities.Groups.MatchID(form.GroupId).ExecuteFirstAsync(token);
|
||||
if (group == default)
|
||||
return result.Invalidate(localizer["Group not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(27014.ToCodedError(localizer["Group not found."]), StatusCodes.Status404NotFound);
|
||||
if (group.OwnerAvatarId == form.AvatarId)
|
||||
return result.Invalidate(localizer["The owner cannot leave the group."]);
|
||||
return result.Invalidate(27015.ToCodedError(localizer["The owner cannot leave the group."]));
|
||||
|
||||
group.Members.RemoveAll(m => !m.IsForeign && m.AvatarId == form.AvatarId);
|
||||
group.UpdatedAt = DateTime.UtcNow;
|
||||
@@ -243,7 +243,7 @@ namespace PrivaPub.Services
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"{nameof(GroupUsersService)}.{nameof(LeaveGroup)}");
|
||||
return result.Invalidate(localizer["Something went wrong."], exception: ex);
|
||||
return result.Invalidate(27016.ToCodedError(localizer["Something went wrong."]), exception: ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,13 +254,13 @@ namespace PrivaPub.Services
|
||||
{
|
||||
var group = await ManagedGroup(rootUserId, form.AvatarId, form.GroupId, token);
|
||||
if (group == default)
|
||||
return result.Invalidate(localizer["Group not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(27017.ToCodedError(localizer["Group not found."]), StatusCodes.Status404NotFound);
|
||||
|
||||
var follower = await dbEntities.Followers
|
||||
.Match(f => f.LocalActorId == group.ID && f.LocalActorKind == LocalActorKind.Group && f.ActorURI == form.MemberActorURI)
|
||||
.ExecuteFirstAsync(token);
|
||||
if (follower == default)
|
||||
return result.Invalidate(localizer["Request not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(27018.ToCodedError(localizer["Request not found."]), StatusCodes.Status404NotFound);
|
||||
|
||||
follower.IsAccepted = true;
|
||||
await DB.Default.SaveAsync(follower, token);
|
||||
@@ -285,7 +285,7 @@ namespace PrivaPub.Services
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"{nameof(GroupUsersService)}.{nameof(ApproveMember)}");
|
||||
return result.Invalidate(localizer["Something went wrong."], exception: ex);
|
||||
return result.Invalidate(27019.ToCodedError(localizer["Something went wrong."]), exception: ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,10 +296,10 @@ namespace PrivaPub.Services
|
||||
? default
|
||||
: await dbEntities.Groups.Match(g => g.InvitationCode == invitationCode && !g.DeletionAt.HasValue).ExecuteFirstAsync(token);
|
||||
if (group == default)
|
||||
return result.Invalidate(localizer["Invalid invitation."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(27020.ToCodedError(localizer["Invalid invitation."]), StatusCodes.Status404NotFound);
|
||||
if (!string.IsNullOrEmpty(group.HashedInvitationPassword)
|
||||
&& (string.IsNullOrEmpty(invitationPassword) || !passwordHasher.Check(group.HashedInvitationPassword, invitationPassword).verified))
|
||||
return result.Invalidate(localizer["Invalid password."], StatusCodes.Status406NotAcceptable);
|
||||
return result.Invalidate(27021.ToCodedError(localizer["Invalid password."]), StatusCodes.Status406NotAcceptable);
|
||||
result.Data = group;
|
||||
return result;
|
||||
}
|
||||
@@ -313,7 +313,7 @@ namespace PrivaPub.Services
|
||||
{
|
||||
var group = await ManagedGroup(rootUserId, avatarId, groupId, token);
|
||||
if (group == default)
|
||||
return result.Invalidate(localizer["Group not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(27022.ToCodedError(localizer["Group not found."]), StatusCodes.Status404NotFound);
|
||||
|
||||
var members = new List<ViewGroupMember>();
|
||||
foreach (var member in group.Members)
|
||||
@@ -346,7 +346,7 @@ namespace PrivaPub.Services
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"{nameof(GroupUsersService)}.{nameof(GetMembers)}");
|
||||
return result.Invalidate(localizer["Something went wrong."], exception: ex);
|
||||
return result.Invalidate(27023.ToCodedError(localizer["Something went wrong."]), exception: ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,12 +370,12 @@ namespace PrivaPub.Services
|
||||
{
|
||||
var group = await ManagedGroup(rootUserId, form.AvatarId, form.GroupId, token);
|
||||
if (group == default)
|
||||
return result.Invalidate(localizer["Group not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(27024.ToCodedError(localizer["Group not found."]), StatusCodes.Status404NotFound);
|
||||
var request = await dbEntities.Followers
|
||||
.Match(f => f.LocalActorId == group.ID && f.LocalActorKind == LocalActorKind.Group && f.ActorURI == form.MemberActorURI && !f.IsAccepted)
|
||||
.ExecuteFirstAsync(token);
|
||||
if (request == default)
|
||||
return result.Invalidate(localizer["Request not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(27025.ToCodedError(localizer["Request not found."]), StatusCodes.Status404NotFound);
|
||||
await DB.Default.DeleteAsync<Follower>(request.ID);
|
||||
await RejectFollow(group, request, token);
|
||||
return result;
|
||||
@@ -383,7 +383,7 @@ namespace PrivaPub.Services
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"{nameof(GroupUsersService)}.{nameof(RejectMember)}");
|
||||
return result.Invalidate(localizer["Something went wrong."], exception: ex);
|
||||
return result.Invalidate(27026.ToCodedError(localizer["Something went wrong."]), exception: ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,15 +396,15 @@ namespace PrivaPub.Services
|
||||
{
|
||||
var group = await ManagedGroup(rootUserId, form.AvatarId, form.GroupId, token);
|
||||
if (group == default)
|
||||
return result.Invalidate(localizer["Group not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(27027.ToCodedError(localizer["Group not found."]), StatusCodes.Status404NotFound);
|
||||
var localMember = await localActors.FindByUri(form.MemberActorURI, token);
|
||||
var member = group.Members.FirstOrDefault(m => localMember is { Kind: LocalActorKind.Person }
|
||||
? !m.IsForeign && m.AvatarId == localMember.Id
|
||||
: m.IsForeign && m.AvatarId == form.MemberActorURI);
|
||||
if (member == default)
|
||||
return result.Invalidate(localizer["Member not found."], StatusCodes.Status404NotFound);
|
||||
return result.Invalidate(27028.ToCodedError(localizer["Member not found."]), StatusCodes.Status404NotFound);
|
||||
if (member.Role == GroupRole.Owner)
|
||||
return result.Invalidate(localizer["The owner cannot leave the group."]);
|
||||
return result.Invalidate(27029.ToCodedError(localizer["The owner cannot leave the group."]));
|
||||
|
||||
group.Members.Remove(member);
|
||||
group.UpdatedAt = DateTime.UtcNow;
|
||||
@@ -426,7 +426,7 @@ namespace PrivaPub.Services
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"{nameof(GroupUsersService)}.{nameof(RemoveMember)}");
|
||||
return result.Invalidate(localizer["Something went wrong."], exception: ex);
|
||||
return result.Invalidate(27030.ToCodedError(localizer["Something went wrong."]), exception: ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user