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
@@ -48,7 +48,7 @@ namespace PrivaPub.Controllers.ClientToServer
|
||||
return root is { IsBanned: false, DeletedAt: null } && root.Policies.Contains(Policies.IsAdmin) ? root : default;
|
||||
}
|
||||
|
||||
IActionResult Refused(int status, string message) => StatusCode(status, new WebResult().Invalidate(localizer[message], status));
|
||||
IActionResult Refused(int status, string message, int errorCode) => StatusCode(status, new WebResult().Invalidate(errorCode.ToCodedError(localizer[message]), status));
|
||||
|
||||
#region settings
|
||||
|
||||
@@ -68,10 +68,10 @@ namespace PrivaPub.Controllers.ClientToServer
|
||||
return Forbid();
|
||||
var contact = Clean(form.ContactAccountId);
|
||||
if (contact != default && !await IsContactable(contact, token))
|
||||
return Refused(StatusCodes.Status422UnprocessableEntity, "The contact account must be a persona of this server.");
|
||||
return Refused(StatusCodes.Status422UnprocessableEntity, "The contact account must be a persona of this server.", 16003);
|
||||
var rules = form.Rules ?? new();
|
||||
if (rules.Count > ServerSettingsForm.MaxRules || rules.Any(r => string.IsNullOrWhiteSpace(r?.Text)))
|
||||
return Refused(StatusCodes.Status422UnprocessableEntity, "Every rule needs its text, and there can be 50 at most.");
|
||||
return Refused(StatusCodes.Status422UnprocessableEntity, "Every rule needs its text, and there can be 50 at most.", 16004);
|
||||
|
||||
var changed = new List<string>();
|
||||
var ruleActs = new List<(string Action, ServerRule Rule)>();
|
||||
@@ -182,7 +182,7 @@ namespace PrivaPub.Controllers.ClientToServer
|
||||
var file = Request.HasFormContentType ? (await Request.ReadFormAsync(token)).Files["file"] : default;
|
||||
var outcome = await media.ServerImage(Thumbnail, file, token);
|
||||
if (!outcome.Ok)
|
||||
return StatusCode(outcome.Status, new WebResult().Invalidate(outcome.Error, outcome.Status));
|
||||
return StatusCode(outcome.Status, new WebResult().Invalidate(16002.ToCodedError(outcome.Error), outcome.Status));
|
||||
var previous = default(string);
|
||||
var saved = await instanceSettings.Update(settings =>
|
||||
{
|
||||
@@ -348,9 +348,9 @@ namespace PrivaPub.Controllers.ClientToServer
|
||||
|
||||
IActionResult Invalid(AnnouncementForm form) =>
|
||||
string.IsNullOrWhiteSpace(form.Text)
|
||||
? Refused(StatusCodes.Status422UnprocessableEntity, "An announcement needs its text.")
|
||||
? Refused(StatusCodes.Status422UnprocessableEntity, "An announcement needs its text.", 16005)
|
||||
: form.StartsAt != default && form.EndsAt != default && form.EndsAt < form.StartsAt
|
||||
? Refused(StatusCodes.Status422UnprocessableEntity, "An announcement can't end before it starts.")
|
||||
? Refused(StatusCodes.Status422UnprocessableEntity, "An announcement can't end before it starts.", 16006)
|
||||
: default;
|
||||
|
||||
static AnnouncementDraft Draft(AnnouncementForm form) => new(form.Text, form.StartsAt, form.EndsAt, form.AllDay, form.IsPublished);
|
||||
@@ -400,11 +400,11 @@ namespace PrivaPub.Controllers.ClientToServer
|
||||
var id = form.AccountId?.Trim();
|
||||
var picked = await Pickable(id, token);
|
||||
if (picked == default)
|
||||
return Refused(StatusCodes.Status404NotFound, "No such account to suggest.");
|
||||
return Refused(StatusCodes.Status404NotFound, "No such account to suggest.", 16007);
|
||||
if (instanceSettings.Current.StaffPicks.Contains(id))
|
||||
return Refused(StatusCodes.Status409Conflict, "This account is suggested already.");
|
||||
return Refused(StatusCodes.Status409Conflict, "This account is suggested already.", 16008);
|
||||
if (instanceSettings.Current.StaffPicks.Count >= MaxStaffPicks)
|
||||
return Refused(StatusCodes.Status422UnprocessableEntity, "40 accounts at most are suggested.");
|
||||
return Refused(StatusCodes.Status422UnprocessableEntity, "40 accounts at most are suggested.", 16009);
|
||||
var saved = await instanceSettings.Update(settings =>
|
||||
{
|
||||
if (!settings.StaffPicks.Contains(id))
|
||||
@@ -495,13 +495,13 @@ namespace PrivaPub.Controllers.ClientToServer
|
||||
var address = form.Address?.Trim();
|
||||
if (!Uri.TryCreate(address, UriKind.Absolute, out var uri) || uri.Scheme != Uri.UriSchemeHttps || !string.IsNullOrEmpty(uri.UserInfo)
|
||||
|| !string.IsNullOrEmpty(uri.Fragment))
|
||||
return Refused(StatusCodes.Status422UnprocessableEntity, "A relay is named by the https address of its actor or its inbox.");
|
||||
return Refused(StatusCodes.Status422UnprocessableEntity, "A relay is named by the https address of its actor or its inbox.", 16010);
|
||||
if (relays.Configured.Contains(address))
|
||||
return Refused(StatusCodes.Status409Conflict, "The configuration names this relay already.");
|
||||
return Refused(StatusCodes.Status409Conflict, "The configuration names this relay already.", 16011);
|
||||
if (instanceSettings.Current.Relays.Contains(address))
|
||||
return Ok(await RelayViews(instanceSettings.Current, token));
|
||||
if (instanceSettings.Current.Relays.Count >= MaxSettingsRelays)
|
||||
return Refused(StatusCodes.Status422UnprocessableEntity, "The settings name 20 relays at most.");
|
||||
return Refused(StatusCodes.Status422UnprocessableEntity, "The settings name 20 relays at most.", 16012);
|
||||
var saved = await instanceSettings.Update(settings =>
|
||||
{
|
||||
if (!settings.Relays.Contains(address))
|
||||
@@ -521,7 +521,7 @@ namespace PrivaPub.Controllers.ClientToServer
|
||||
return Forbid();
|
||||
address = address?.Trim();
|
||||
if (relays.Configured.Contains(address))
|
||||
return Refused(StatusCodes.Status409Conflict, "This relay is named by the configuration (Federation:Relays): remove it there.");
|
||||
return Refused(StatusCodes.Status409Conflict, "This relay is named by the configuration (Federation:Relays): remove it there.", 16013);
|
||||
if (string.IsNullOrEmpty(address) || !instanceSettings.Current.Relays.Contains(address))
|
||||
return NotFound();
|
||||
var saved = await instanceSettings.Update(settings => settings.Relays.Remove(address), admin.ID, token);
|
||||
|
||||
Reference in new issue
Block a user