Every failure the server answers with names its own error code
Build / Build (push) Successful in 34s
Deploy / privapub.thepra.dev (push) Successful in 57s
Deploy / Release notes on the Releases tab (push) Successful in 3s

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:
thepraandClaude Opus 5.5 committed 2026-11-10 08:11:24 +01:00
1 parent f3fdeaf038
commit c2f439d1e9
25 files changed
+268 -224

No files matched your search

@@ -76,7 +76,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(User)}.{nameof(RemoveUsers)}()");
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(10001.ToCodedError(localizer["Something went wrong."])));
}
}
@@ -110,7 +110,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(User)}.{nameof(BanUsers)}()");
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(10002.ToCodedError(localizer["Something went wrong."])));
}
}
@@ -136,7 +136,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(User)}.{nameof(UnbanUsers)}()");
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(10003.ToCodedError(localizer["Something went wrong."])));
}
}
@@ -183,9 +183,9 @@ namespace PrivaPub.Controllers.ClientToServer
public async Task<IActionResult> Role(string id, RootRoleForm form, CancellationToken token)
{
if (!ModelState.IsValid || !RootUser.TryParseRole(form.Role, out var role))
return UnprocessableEntity(new WebResult().Invalidate(localizer["Unknown role."], StatusCodes.Status422UnprocessableEntity));
return UnprocessableEntity(new WebResult().Invalidate(10004.ToCodedError(localizer["Unknown role."]), StatusCodes.Status422UnprocessableEntity));
if (id == User.GetUserId())
return Conflict(new WebResult().Invalidate(localizer["You can't change your own role."], StatusCodes.Status409Conflict));
return Conflict(new WebResult().Invalidate(10005.ToCodedError(localizer["You can't change your own role."]), StatusCodes.Status409Conflict));
var root = await DB.Default.Find<RootUser>().MatchID(id).Match(u => u.DeletedAt == null).ExecuteFirstAsync(token);
if (root == default)
return NotFound();
@@ -193,7 +193,7 @@ namespace PrivaPub.Controllers.ClientToServer
if (was == role)
return Ok((await Views(new List<RootUser> { root }, token))[0]);
if (was == RootRole.Admin && !await OtherAdministrators(root.ID, token))
return Conflict(new WebResult().Invalidate(localizer["The last administrator can't be demoted."], StatusCodes.Status409Conflict));
return Conflict(new WebResult().Invalidate(10006.ToCodedError(localizer["The last administrator can't be demoted."]), StatusCodes.Status409Conflict));
root.SetRole(role);
await DB.Default.Update<RootUser>().MatchID(root.ID).Modify(u => u.Policies, root.Policies).Modify(u => u.UpdatedAt, root.UpdatedAt)
.ExecuteAsync(CancellationToken.None);
@@ -202,7 +202,7 @@ namespace PrivaPub.Controllers.ClientToServer
{
root.SetRole(was);
await DB.Default.Update<RootUser>().MatchID(root.ID).Modify(u => u.Policies, root.Policies).ExecuteAsync(CancellationToken.None);
return Conflict(new WebResult().Invalidate(localizer["The last administrator can't be demoted."], StatusCodes.Status409Conflict));
return Conflict(new WebResult().Invalidate(10007.ToCodedError(localizer["The last administrator can't be demoted."]), StatusCodes.Status409Conflict));
}
if (role == RootRole.Admin)
await ServerSetup.Seal(root.ID, default);//an administrator exists: the client's setup is closed
@@ -221,7 +221,7 @@ namespace PrivaPub.Controllers.ClientToServer
public async Task<IActionResult> ResetTotp(string id, CancellationToken token)
{
if (id == User.GetUserId())
return Conflict(new WebResult().Invalidate(localizer["Turn your own two-factor sign-in off from your account."], StatusCodes.Status409Conflict));
return Conflict(new WebResult().Invalidate(10008.ToCodedError(localizer["Turn your own two-factor sign-in off from your account."]), StatusCodes.Status409Conflict));
var root = await DB.Default.Find<RootUser>().MatchID(id).Match(u => u.DeletedAt == null).ExecuteFirstAsync(token);
if (root == default)
return NotFound();
@@ -236,9 +236,9 @@ namespace PrivaPub.Controllers.ClientToServer
public async Task<IActionResult> DeletePersona(string id, AdminPasswordForm form, [FromServices] IPersonaRemoval personas, CancellationToken token)
{
if (!ModelState.IsValid)
return BadRequest(new WebResult().Invalidate(localizer["Invalid model."]));
return BadRequest(new WebResult().Invalidate(10009.ToCodedError(localizer["Invalid model."])));
if (!await rootUsersService.PasswordMatches(User.GetUserId(), form.Password, token))
return StatusCode(StatusCodes.Status403Forbidden, new WebResult().Invalidate(localizer[Services.RootUsersService.NoMatch], StatusCodes.Status403Forbidden));
return StatusCode(StatusCodes.Status403Forbidden, new WebResult().Invalidate(10010.ToCodedError(localizer[Services.RootUsersService.NoMatch]), StatusCodes.Status403Forbidden));
var avatar = await dbEntities.Avatars.MatchID(id).Match(a => !a.DeletionAt.HasValue).ExecuteFirstAsync(token);
if (avatar == default)
return NotFound();
@@ -253,9 +253,9 @@ namespace PrivaPub.Controllers.ClientToServer
public async Task<IActionResult> DeleteGroup(string id, AdminPasswordForm form, [FromServices] IGroupRemoval groups, CancellationToken token)
{
if (!ModelState.IsValid)
return BadRequest(new WebResult().Invalidate(localizer["Invalid model."]));
return BadRequest(new WebResult().Invalidate(10011.ToCodedError(localizer["Invalid model."])));
if (!await rootUsersService.PasswordMatches(User.GetUserId(), form.Password, token))
return StatusCode(StatusCodes.Status403Forbidden, new WebResult().Invalidate(localizer[Services.RootUsersService.NoMatch], StatusCodes.Status403Forbidden));
return StatusCode(StatusCodes.Status403Forbidden, new WebResult().Invalidate(10012.ToCodedError(localizer[Services.RootUsersService.NoMatch]), StatusCodes.Status403Forbidden));
var group = await dbEntities.Groups.MatchID(id).Match(g => !g.DeletionAt.HasValue).ExecuteFirstAsync(token);
if (group == default)
return NotFound();