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();
@@ -64,7 +64,7 @@ namespace PrivaPub.Controllers.ClientToServer
if (admin == default)
return Forbid();
if (await MaintenanceLock.Current(token) is { } held)
return Conflict(new WebResult().Invalidate(localizer["A {0} is running.", held.What]));
return Conflict(new WebResult().Invalidate(11001.ToCodedError(localizer["A {0} is running.", held.What])));
await log.Write(admin.ID, Models.AdminActions.BackupCreate, Models.AdminTargets.Backup, default, "manual", token: token);
_ = Task.Run(async () =>
{
@@ -91,7 +91,7 @@ namespace PrivaPub.Controllers.ClientToServer
if (admin == default)
return Forbid();
if (RestoreMarker.Read(backups.Root) is { } waiting && (waiting.Backup == id || waiting.PreRestore == id))
return Conflict(new WebResult().Invalidate(localizer["A restore waits for this backup."]));
return Conflict(new WebResult().Invalidate(11002.ToCodedError(localizer["A restore waits for this backup."])));
if (!backups.Delete(id))
return NotFound();
await log.Write(admin.ID, Models.AdminActions.BackupDelete, Models.AdminTargets.Backup, id, id, token: token);
@@ -106,7 +106,7 @@ namespace PrivaPub.Controllers.ClientToServer
if (admin == default)
return Forbid();
if (!PasswordHolds(admin, form.Password))
return UnprocessableEntity(new WebResult().Invalidate(localizer["Wrong password."]));
return UnprocessableEntity(new WebResult().Invalidate(11003.ToCodedError(localizer["Wrong password."])));
if (backups.Find(id) == default)
return NotFound();
var (ticket, expires) = transfers.Ticket(id);
@@ -187,10 +187,10 @@ namespace PrivaPub.Controllers.ClientToServer
if (await Administrator(token) == default)
return Forbid();
if (await MaintenanceLock.Current(token) is { What: "restore" })
return Conflict(new WebResult().Invalidate(localizer["A {0} is running.", "restore"]));
return Conflict(new WebResult().Invalidate(11004.ToCodedError(localizer["A {0} is running.", "restore"])));
var (backup, error) = await transfers.Finish(id, token);
if (backup == default)
return UnprocessableEntity(new WebResult().Invalidate(error));
return UnprocessableEntity(new WebResult().Invalidate(11005.ToCodedError(error)));
return Ok(View(backup, 0, ServerBackup.CodeMigration()));
}
@@ -210,12 +210,12 @@ namespace PrivaPub.Controllers.ClientToServer
if (admin == default)
return Forbid();
if (!PasswordHolds(admin, form.Password))
return UnprocessableEntity(new WebResult().Invalidate(localizer["Wrong password."]));
return UnprocessableEntity(new WebResult().Invalidate(11006.ToCodedError(localizer["Wrong password."])));
if (!string.Equals(form.Host?.Trim(), HostName, StringComparison.OrdinalIgnoreCase))
return UnprocessableEntity(new WebResult().Invalidate(localizer["Type this server's host to restore it."]));
return UnprocessableEntity(new WebResult().Invalidate(11007.ToCodedError(localizer["Type this server's host to restore it."])));
var refused = await ServerRestore.Request(backups.Context(), id, admin.UserName, token);
if (refused != default)
return UnprocessableEntity(new WebResult().Invalidate(refused));
return UnprocessableEntity(new WebResult().Invalidate(11008.ToCodedError(refused)));
logger.LogWarning("{Admin} asked to restore {Backup}", admin.UserName, id);
await log.Write(admin.ID, Models.AdminActions.BackupRestore, Models.AdminTargets.Backup, id, id, token: token);
return Accepted();
@@ -40,7 +40,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(DataController)}.{nameof(Languages)}()");
return BadRequest(result.Invalidate("Something went wrong.", exception: ex));
return BadRequest(result.Invalidate(12001.ToCodedError("Something went wrong."), exception: ex));
}
}
}
@@ -34,7 +34,7 @@ namespace PrivaPub.Controllers.ClientToServer
{
var domain = DomainBlocks.Normalise(form.Domain);
if (!ModelState.IsValid || Uri.CheckHostName(domain) != UriHostNameType.Dns)
return BadRequest(new WebResult().Invalidate(localizer["Invalid model."]));
return BadRequest(new WebResult().Invalidate(13001.ToCodedError(localizer["Invalid model."])));
var block = await DB.Default.UpdateAndGet<DomainBlock>()
.Match(b => b.Domain == domain)
@@ -43,7 +43,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));
[HttpGet, Route(ApiPaths.EmojiAdmin.GET_List)]
public async Task<IActionResult> List(CancellationToken token)
@@ -64,10 +64,10 @@ namespace PrivaPub.Controllers.ClientToServer
var key = form.Shortcode.ToLowerInvariant();
var existing = await DB.Default.Find<LocalEmoji>().Match(e => e.Key == key).ExecuteFirstAsync(token);
if (existing != default && (existing.DeletedAt == default || existing.Shortcode != form.Shortcode))
return Refused(StatusCodes.Status409Conflict, "This shortcode is taken.");
return Refused(StatusCodes.Status409Conflict, "This shortcode is taken.", 14004);
var outcome = await media.EmojiImage(form.Shortcode, await Picture(token), token);
if (!outcome.Ok)
return StatusCode(outcome.Status, new WebResult().Invalidate(outcome.Error, outcome.Status));
return StatusCode(outcome.Status, new WebResult().Invalidate(14002.ToCodedError(outcome.Error), outcome.Status));
var now = DateTime.UtcNow;
var emoji = existing ?? new LocalEmoji { Shortcode = form.Shortcode, Key = key, CreatedAt = now };
@@ -93,7 +93,7 @@ namespace PrivaPub.Controllers.ClientToServer
if (!saved)
{
await media.Trash(m => m.ID == outcome.Attachment.ID, "emoji not saved", token);
return Refused(StatusCodes.Status409Conflict, "This shortcode is taken.");
return Refused(StatusCodes.Status409Conflict, "This shortcode is taken.", 14005);
}
await LocalEmojis.Reload(CancellationToken.None);
var notes = new[] { existing != default ? "added again" : default, emoji.Disabled ? "disabled" : default, Animated(emoji) }.Where(n => n != default).ToList();
@@ -133,7 +133,7 @@ namespace PrivaPub.Controllers.ClientToServer
{
outcome = await media.EmojiImage(emoji.Shortcode, image, token);
if (!outcome.Ok)
return StatusCode(outcome.Status, new WebResult().Invalidate(outcome.Error, outcome.Status));
return StatusCode(outcome.Status, new WebResult().Invalidate(14003.ToCodedError(outcome.Error), outcome.Status));
Picture(emoji, outcome.Attachment, now);
changed.Add("image");
}
@@ -63,18 +63,18 @@ namespace PrivaPub.Controllers.ClientToServer
return Invalid();
var rootId = User.GetUserId();
if (!await users.PasswordMatches(rootId, form.Password, token))
return StatusCode(StatusCodes.Status403Forbidden, new WebResult().Invalidate(localizer[RootUsersService.NoMatch], StatusCodes.Status403Forbidden));
return StatusCode(StatusCodes.Status403Forbidden, new WebResult().Invalidate(15001.ToCodedError(localizer[RootUsersService.NoMatch]), StatusCodes.Status403Forbidden));
var owns = await dbEntities.RootToAvatars.Match(ra => ra.RootId == rootId && ra.AvatarId == form.AvatarId).ExecuteAnyAsync(token);
var group = owns ? await dbEntities.Groups.MatchID(form.GroupId).Match(g => !g.DeletionAt.HasValue).ExecuteFirstAsync(token) : default;
if (group == default)
return NotFound(new WebResult().Invalidate(localizer["Group not found."], StatusCodes.Status404NotFound));
return NotFound(new WebResult().Invalidate(15002.ToCodedError(localizer["Group not found."]), StatusCodes.Status404NotFound));
if (group.OwnerAvatarId != form.AvatarId)
return StatusCode(StatusCodes.Status403Forbidden, new WebResult().Invalidate(localizer["Only the group's owner can delete it."], StatusCodes.Status403Forbidden));
return StatusCode(StatusCodes.Status403Forbidden, new WebResult().Invalidate(15003.ToCodedError(localizer["Only the group's owner can delete it."]), StatusCodes.Status403Forbidden));
await groups.Remove(group.ID, CancellationToken.None);
return Ok();
}
IActionResult Invalid() => BadRequest(new WebResult().Invalidate(localizer["Invalid model."]));
IActionResult Invalid() => BadRequest(new WebResult().Invalidate(15004.ToCodedError(localizer["Invalid model."])));
IActionResult Answer(WebResult result) => result.IsValid ? Ok(result.Data) : StatusCode(result.StatusCode, result);
}
@@ -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);
@@ -67,7 +67,7 @@ namespace PrivaPub.Controllers.ClientToServer
form ??= new ResolveReportForm();
var action = string.IsNullOrWhiteSpace(form.Action) ? ModerationActions.None : form.Action.Trim().ToLowerInvariant();
if (!ModerationActions.IsResolution(action))
return UnprocessableEntity(new WebResult().Invalidate(localizer["Unknown moderation action."], StatusCodes.Status422UnprocessableEntity));
return UnprocessableEntity(new WebResult().Invalidate(17001.ToCodedError(localizer["Unknown moderation action."]), StatusCodes.Status422UnprocessableEntity));
var by = User.GetUserId();
var report = await DB.Default.Find<Report>().MatchID(id).ExecuteFirstAsync(token);
if (report == default)
@@ -81,7 +81,7 @@ namespace PrivaPub.Controllers.ClientToServer
break;
case ModerationActions.RemovePosts:
if (report.PostIds.Count == 0)
return UnprocessableEntity(new WebResult().Invalidate(localizer["The report names no posts."], StatusCodes.Status422UnprocessableEntity));
return UnprocessableEntity(new WebResult().Invalidate(17002.ToCodedError(localizer["The report names no posts."]), StatusCodes.Status422UnprocessableEntity));
foreach (var postId in report.PostIds)
{
var removed = await accountModeration.RemovePost(by, postId, form.Note, form.Warning, report.ID, token);
@@ -172,7 +172,7 @@ namespace PrivaPub.Controllers.ClientToServer
public async Task<IActionResult> Moderate(ModerateAccountForm form, CancellationToken token)
{
if (!ModelState.IsValid)
return BadRequest(new WebResult().Invalidate(localizer["Invalid model."]));
return BadRequest(new WebResult().Invalidate(17003.ToCodedError(localizer["Invalid model."])));
var result = await accountModeration.Moderate(User.GetUserId(), form.AccountId, form.Action.Trim().ToLowerInvariant(), form.Note, form.Warning, default, token);
return result.IsValid ? Ok(result.Data) : StatusCode(result.StatusCode, result);
}
@@ -182,7 +182,7 @@ namespace PrivaPub.Controllers.ClientToServer
public async Task<IActionResult> RemovePost(RemovePostForm form, CancellationToken token)
{
if (!ModelState.IsValid)
return BadRequest(new WebResult().Invalidate(localizer["Invalid model."]));
return BadRequest(new WebResult().Invalidate(17004.ToCodedError(localizer["Invalid model."])));
var result = await accountModeration.RemovePost(User.GetUserId(), form.PostId, form.Note, form.Warning, default, token);
return result.IsValid ? Ok() : StatusCode(result.StatusCode, result);
}
@@ -38,7 +38,7 @@ namespace PrivaPub.Controllers.ClientToServer
return NotFound();
var state = await PersonaArchives.Of(avatarId, token);
if (state.ExportState is "queued" or "running")
return Conflict(new WebResult().Invalidate("The archive is being made."));
return Conflict(new WebResult().Invalidate(18001.ToCodedError("The archive is being made.")));
state.ExportState = "queued";
state.ExportAskedAt = DateTime.UtcNow;
state.ExportError = default;
@@ -112,12 +112,12 @@ namespace PrivaPub.Controllers.ClientToServer
return NotFound();
// a suspended persona may take its archive away, never bring one in (R6): an import follows, blocks and posts
if (await DB.Default.Find<Avatar>().MatchID(avatarId).Match(a => a.SuspendedAt != null).ExecuteAnyAsync(token))
return StatusCode(StatusCodes.Status403Forbidden, new WebResult().Invalidate("This persona is suspended.", StatusCodes.Status403Forbidden));
return StatusCode(StatusCodes.Status403Forbidden, new WebResult().Invalidate(18002.ToCodedError("This persona is suspended."), StatusCodes.Status403Forbidden));
var state = await PersonaArchives.Of(avatarId, token);
if (state.ImportState is "queued" or "running")
return Conflict(new WebResult().Invalidate("An import is running."));
return Conflict(new WebResult().Invalidate(18003.ToCodedError("An import is running.")));
if (form.Parts.Count == 0 || form.Parts.Any(p => !PersonaArchives.Parts.Contains(p)))
return UnprocessableEntity(new WebResult().Invalidate("Choose what to import."));
return UnprocessableEntity(new WebResult().Invalidate(18004.ToCodedError("Choose what to import.")));
if (transfers.Owner(form.UploadId) != User.GetUserId())
return NotFound();
var path = transfers.Take(form.UploadId, PersonaArchives.Folder(backups.Root, avatarId), $"import-{form.UploadId}.zip");
@@ -128,7 +128,7 @@ namespace PrivaPub.Controllers.ClientToServer
if (archive?.Has("actor.json") != true)
{
System.IO.File.Delete(path);
return UnprocessableEntity(new WebResult().Invalidate(refused ?? "the archive has no actor.json"));
return UnprocessableEntity(new WebResult().Invalidate(18005.ToCodedError(refused ?? "the archive has no actor.json")));
}
state.ImportState = "queued";
state.ImportAskedAt = DateTime.UtcNow;
@@ -45,7 +45,7 @@ namespace PrivaPub.Controllers.ClientToServer
public async Task<IActionResult> InsertDm(InsertDmForm form, CancellationToken token) =>
!ModelState.IsValid ? Invalid() : Answer(await postsService.InsertDm(User.GetUserId(), form, token));
IActionResult Invalid() => BadRequest(new WebResult().Invalidate(localizer["Invalid model."]));
IActionResult Invalid() => BadRequest(new WebResult().Invalidate(19001.ToCodedError(localizer["Invalid model."])));
IActionResult Answer(WebResult result) => result.IsValid ? Ok(result.Data) : StatusCode(result.StatusCode, result);
}
@@ -30,7 +30,7 @@ namespace PrivaPub.Controllers.ClientToServer
{
var result = new WebResult();
if (!ModelState.IsValid)
return BadRequest(result.Invalidate(localizer["Invalid model."]));
return BadRequest(result.Invalidate(20001.ToCodedError(localizer["Invalid model."])));
try
{
model.RootId = User.GetUserId();
@@ -43,7 +43,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(PrivateAvatarController)}.{nameof(InsertAvatar)}()");
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(20002.ToCodedError(localizer["Something went wrong."])));
}
}
@@ -54,13 +54,13 @@ namespace PrivaPub.Controllers.ClientToServer
[FromServices] Services.IPersonaRemoval personas, [FromServices] StaticServices.DbEntities dbEntities, CancellationToken token)
{
if (!ModelState.IsValid)
return BadRequest(new WebResult().Invalidate(localizer["Invalid model."]));
return BadRequest(new WebResult().Invalidate(20003.ToCodedError(localizer["Invalid model."])));
var rootId = User.GetUserId();
if (!await users.PasswordMatches(rootId, form.Password, token))
return StatusCode(StatusCodes.Status403Forbidden, new WebResult().Invalidate(localizer[Services.RootUsersService.NoMatch], StatusCodes.Status403Forbidden));
return StatusCode(StatusCodes.Status403Forbidden, new WebResult().Invalidate(20004.ToCodedError(localizer[Services.RootUsersService.NoMatch]), StatusCodes.Status403Forbidden));
if (!await dbEntities.RootToAvatars.Match(ra => ra.RootId == rootId && ra.AvatarId == form.AvatarId).ExecuteAnyAsync(token)
|| !await personas.Remove(form.AvatarId, CancellationToken.None))
return NotFound(new WebResult().Invalidate(localizer["Avatar not found."], StatusCodes.Status404NotFound));
return NotFound(new WebResult().Invalidate(20005.ToCodedError(localizer["Avatar not found."]), StatusCodes.Status404NotFound));
return Ok();
}
@@ -70,7 +70,7 @@ namespace PrivaPub.Controllers.ClientToServer
{
var avatar = await OwnPersona(avatarId, dbEntities, token);
return avatar == default
? NotFound(new WebResult().Invalidate(localizer["Avatar not found."], StatusCodes.Status404NotFound))
? NotFound(new WebResult().Invalidate(20006.ToCodedError(localizer["Avatar not found."]), StatusCodes.Status404NotFound))
: Ok(PreferencesOf(avatar));
}
@@ -78,12 +78,12 @@ namespace PrivaPub.Controllers.ClientToServer
public async Task<IActionResult> SavePreferences(PersonaPreferencesForm form, [FromServices] StaticServices.DbEntities dbEntities, CancellationToken token)
{
if (!ModelState.IsValid)
return BadRequest(new WebResult().Invalidate(localizer["Invalid model."]));
return BadRequest(new WebResult().Invalidate(20007.ToCodedError(localizer["Invalid model."])));
if (!Models.User.ExpandMediaModes.IsKnown(form.ExpandMedia))
return UnprocessableEntity(new WebResult().Invalidate(localizer["Media are shown as default, show_all or hide_all."], StatusCodes.Status422UnprocessableEntity));
return UnprocessableEntity(new WebResult().Invalidate(20008.ToCodedError(localizer["Media are shown as default, show_all or hide_all."]), StatusCodes.Status422UnprocessableEntity));
var avatar = await OwnPersona(form.AvatarId, dbEntities, token);
if (avatar == default)
return NotFound(new WebResult().Invalidate(localizer["Avatar not found."], StatusCodes.Status404NotFound));
return NotFound(new WebResult().Invalidate(20009.ToCodedError(localizer["Avatar not found."]), StatusCodes.Status404NotFound));
await MongoDB.Entities.DB.Default.Update<Models.User.Avatar>().MatchID(avatar.ID)
.Modify(a => a.Settings.ExpandMedia, form.ExpandMedia)
.Modify(a => a.Settings.ExpandSpoilers, form.ExpandSpoilers)
@@ -114,7 +114,7 @@ namespace PrivaPub.Controllers.ClientToServer
{
var result = new WebResult();
if (!ModelState.IsValid)
return BadRequest(result.Invalidate(localizer["Invalid model."]));
return BadRequest(result.Invalidate(20010.ToCodedError(localizer["Invalid model."])));
try
{
model.RootId = User.GetUserId();
@@ -127,7 +127,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(PrivateAvatarController)}.{nameof(UpdateAvatar)}()");
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(20011.ToCodedError(localizer["Something went wrong."])));
}
}
@@ -47,9 +47,9 @@ namespace PrivaPub.Controllers.ClientToServer
if (User.Identity?.IsAuthenticated ?? false) return Redirect("/");
var result = new WebResult();
if (!registrations.CurrentValue.IsOpen)
return StatusCode(StatusCodes.Status403Forbidden, result.Invalidate(localizer[RegistrationOptions.ClosedMessage], StatusCodes.Status403Forbidden));
return StatusCode(StatusCodes.Status403Forbidden, result.Invalidate(21001.ToCodedError(localizer[RegistrationOptions.ClosedMessage]), StatusCodes.Status403Forbidden));
if (!ModelState.IsValid)
return BadRequest(result.Invalidate(localizer["Invalid model."]));
return BadRequest(result.Invalidate(21002.ToCodedError(localizer["Invalid model."])));
try
{
result = await usersService.SignUpAsync(signUpForm, token);
@@ -63,7 +63,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(User)}.{nameof(SignUp)}()");
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(21003.ToCodedError(localizer["Something went wrong."])));
}
}
@@ -73,7 +73,7 @@ namespace PrivaPub.Controllers.ClientToServer
if (User.Identity?.IsAuthenticated ?? false) return Redirect("/");
var result = new WebResult();
if (!ModelState.IsValid)
return BadRequest(result.Invalidate(localizer["Invalid model."]));
return BadRequest(result.Invalidate(21004.ToCodedError(localizer["Invalid model."])));
try
{
result = await usersService.LoginAsync(loginForm, token);
@@ -89,7 +89,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(User)}.{nameof(Login)}()");
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(21005.ToCodedError(localizer["Something went wrong."])));
}
}
@@ -98,7 +98,7 @@ namespace PrivaPub.Controllers.ClientToServer
{
var result = new WebResult();
if (!ModelState.IsValid)
return BadRequest(result.Invalidate(localizer["Invalid model."]));
return BadRequest(result.Invalidate(21006.ToCodedError(localizer["Invalid model."])));
try
{
var invitation = await groupUsersService.GetInvitation(signUpForm.InvitationCode, signUpForm.InvitationPassword, token);
@@ -108,7 +108,7 @@ namespace PrivaPub.Controllers.ClientToServer
var avatarUserName = signUpForm.AvatarUserName?.Trim().ToLowerInvariant();
var personaProblem = await PersonaProblem(avatarUserName, signUpForm.UserName, token);
if (personaProblem != default)
return BadRequest(result.Invalidate(personaProblem));
return BadRequest(result.Invalidate(21007.ToCodedError(personaProblem)));
result = await usersService.SignUpAsync(signUpForm, token);
if (!result.IsValid)
@@ -133,7 +133,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(User)}.{nameof(InvitationSignUp)}()");
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(21008.ToCodedError(localizer["Something went wrong."])));
}
}
@@ -142,7 +142,7 @@ namespace PrivaPub.Controllers.ClientToServer
{
var result = new WebResult();
if (!ModelState.IsValid)
return BadRequest(result.Invalidate(localizer["Invalid model."]));
return BadRequest(result.Invalidate(21009.ToCodedError(localizer["Invalid model."])));
try
{
var invitation = await groupUsersService.GetInvitation(loginForm.InvitationCode, loginForm.InvitationPassword, token);
@@ -163,7 +163,7 @@ namespace PrivaPub.Controllers.ClientToServer
{
var personaProblem = await PersonaProblem(avatarUserName, user.UserName, token);
if (personaProblem != default)
return BadRequest(new WebResult().Invalidate(personaProblem));
return BadRequest(new WebResult().Invalidate(21010.ToCodedError(personaProblem)));
var inserted = await InsertPersona(user.ID, avatarUserName, loginForm.AvatarName, token);
if (!inserted.IsValid)
return StatusCode(inserted.StatusCode, inserted);
@@ -184,7 +184,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(User)}.{nameof(InvitationLogin)}()");
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(21011.ToCodedError(localizer["Something went wrong."])));
}
}
@@ -201,7 +201,7 @@ namespace PrivaPub.Controllers.ClientToServer
if (User.Identity?.IsAuthenticated ?? false) return Redirect("/");
var result = new WebResult();
if (!ModelState.IsValid)
return BadRequest(result.Invalidate(localizer["Invalid model."]));
return BadRequest(result.Invalidate(21012.ToCodedError(localizer["Invalid model."])));
var claimed = false;
var adminId = default(string);
try
@@ -212,7 +212,7 @@ namespace PrivaPub.Controllers.ClientToServer
var avatarUserName = setupForm.AvatarUserName?.Trim().ToLowerInvariant();
var personaProblem = await PersonaProblem(avatarUserName, setupForm.UserName, token);
if (personaProblem != default)
return BadRequest(result.Invalidate(personaProblem));
return BadRequest(result.Invalidate(21013.ToCodedError(personaProblem)));
claimed = await ServerSetup.Claim(token);
if (!claimed)
@@ -242,13 +242,13 @@ namespace PrivaPub.Controllers.ClientToServer
logger.LogError(ex, $"{nameof(User)}.{nameof(SetUp)}()");
if (claimed && adminId == default)
await ServerSetup.Release(CancellationToken.None);
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(21014.ToCodedError(localizer["Something went wrong."])));
}
}
IActionResult SetUpAlready() =>
StatusCode(StatusCodes.Status403Forbidden,
new WebResult().Invalidate(localizer["This server is already set up: joining it takes a group invitation."], StatusCodes.Status403Forbidden));
new WebResult().Invalidate(21015.ToCodedError(localizer["This server is already set up: joining it takes a group invitation."]), StatusCodes.Status403Forbidden));
Task<WebResult> InsertPersona(string rootId, string avatarUserName, string avatarName, CancellationToken token = default) =>
avatarUsersService.InsertAvatar(new InsertAvatarForm
@@ -288,7 +288,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(User)}.{nameof(Logout)}()");
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(21016.ToCodedError(localizer["Something went wrong."])));
}
}
@@ -304,7 +304,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(User)}.{nameof(LogoutEverywhere)}()");
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(21017.ToCodedError(localizer["Something went wrong."])));
}
}
@@ -313,7 +313,7 @@ namespace PrivaPub.Controllers.ClientToServer
[HttpPost, Route(ApiPaths.RootUser.POST_UpdateUser), Authorize(Policy = Policies.IsUser)]
public IActionResult UpdateUser(UserForm userEmailForm) =>
StatusCode(StatusCodes.Status422UnprocessableEntity,
new WebResult().Invalidate(localizer["Changing the address takes your password and a code sent to it."], StatusCodes.Status422UnprocessableEntity));
new WebResult().Invalidate(21018.ToCodedError(localizer["Changing the address takes your password and a code sent to it."]), StatusCodes.Status422UnprocessableEntity));
[HttpGet, Route(ApiPaths.RootUser.GET_Account), Authorize(Policy = Policies.IsUser)]
public async Task<IActionResult> Account(CancellationToken token = default)
@@ -326,7 +326,7 @@ namespace PrivaPub.Controllers.ClientToServer
public async Task<IActionResult> RequestEmailChange(EmailChangeForm form, CancellationToken token = default)
{
if (!ModelState.IsValid)
return BadRequest(new WebResult().Invalidate(localizer["Invalid model."]));
return BadRequest(new WebResult().Invalidate(21019.ToCodedError(localizer["Invalid model."])));
var result = await usersService.RequestEmailChangeAsync(User.GetUserId(), form, token);
return result.IsValid ? Ok(result.Data) : StatusCode(result.StatusCode, result);
}
@@ -335,7 +335,7 @@ namespace PrivaPub.Controllers.ClientToServer
public async Task<IActionResult> VerifyEmail(EmailCodeForm form, CancellationToken token = default)
{
if (!ModelState.IsValid)
return BadRequest(new WebResult().Invalidate(localizer["Invalid model."]));
return BadRequest(new WebResult().Invalidate(21020.ToCodedError(localizer["Invalid model."])));
var result = await usersService.VerifyEmailAsync(User.GetUserId(), form.Code, token);
return result.IsValid ? Ok(result.Data) : StatusCode(result.StatusCode, result);
}
@@ -344,7 +344,7 @@ namespace PrivaPub.Controllers.ClientToServer
public async Task<IActionResult> TotpSetup(PasswordForm form, CancellationToken token = default)
{
if (!ModelState.IsValid)
return BadRequest(new WebResult().Invalidate(localizer["Invalid model."]));
return BadRequest(new WebResult().Invalidate(21021.ToCodedError(localizer["Invalid model."])));
var result = await usersService.TotpSetupAsync(User.GetUserId(), form.Password, token);
return result.IsValid ? Ok(result.Data) : StatusCode(result.StatusCode, result);
}
@@ -354,7 +354,7 @@ namespace PrivaPub.Controllers.ClientToServer
public async Task<IActionResult> TotpEnable(TotpCodeForm form, CancellationToken token = default)
{
if (!ModelState.IsValid)
return BadRequest(new WebResult().Invalidate(localizer["Invalid model."]));
return BadRequest(new WebResult().Invalidate(21022.ToCodedError(localizer["Invalid model."])));
var result = await usersService.TotpEnableAsync(User.GetUserId(), form.Code, token);
if (!result.IsValid)
return StatusCode(result.StatusCode, result);
@@ -366,7 +366,7 @@ namespace PrivaPub.Controllers.ClientToServer
public async Task<IActionResult> TotpDisable(TotpDisableForm form, CancellationToken token = default)
{
if (!ModelState.IsValid)
return BadRequest(new WebResult().Invalidate(localizer["Invalid model."]));
return BadRequest(new WebResult().Invalidate(21023.ToCodedError(localizer["Invalid model."])));
var result = await usersService.TotpDisableAsync(User.GetUserId(), form.Password, form.Code, token);
return result.IsValid ? Ok(result.Data) : StatusCode(result.StatusCode, result);
}
@@ -375,7 +375,7 @@ namespace PrivaPub.Controllers.ClientToServer
public async Task<IActionResult> RemoveEmail(PasswordForm form, CancellationToken token = default)
{
if (!ModelState.IsValid)
return BadRequest(new WebResult().Invalidate(localizer["Invalid model."]));
return BadRequest(new WebResult().Invalidate(21024.ToCodedError(localizer["Invalid model."])));
var result = await usersService.RemoveEmailAsync(User.GetUserId(), form.Password, token);
return result.IsValid ? Ok(result.Data) : StatusCode(result.StatusCode, result);
}
@@ -385,7 +385,7 @@ namespace PrivaPub.Controllers.ClientToServer
{
var result = new WebResult();
if (!ModelState.IsValid)
return BadRequest(result.Invalidate(localizer["Invalid model."]));
return BadRequest(result.Invalidate(21025.ToCodedError(localizer["Invalid model."])));
try
{
result = await usersService.UpdateUserSettingsAsync(userSettings, User.GetUserId(), token);
@@ -397,7 +397,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(User)}.{nameof(UpdateUserSettings)}()");
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(21026.ToCodedError(localizer["Something went wrong."])));
}
}
@@ -406,7 +406,7 @@ namespace PrivaPub.Controllers.ClientToServer
{
var result = new WebResult();
if (!ModelState.IsValid)
return BadRequest(result.Invalidate(localizer["Invalid model."]));
return BadRequest(result.Invalidate(21027.ToCodedError(localizer["Invalid model."])));
try
{
result = await usersService.UpdateUserPasswordAsync(userPasswordForm, User.GetUserId(), token);
@@ -420,7 +420,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(User)}.{nameof(UpdatePassword)}()");
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(21028.ToCodedError(localizer["Something went wrong."])));
}
}
@@ -447,7 +447,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(User)}.{nameof(GetUserSettings)}()");
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(21029.ToCodedError(localizer["Something went wrong."])));
}
}
@@ -456,7 +456,7 @@ namespace PrivaPub.Controllers.ClientToServer
{
var result = new WebResult();
if (!ModelState.IsValid)
return BadRequest(result.Invalidate(localizer["Invalid model."]));
return BadRequest(result.Invalidate(21030.ToCodedError(localizer["Invalid model."])));
try
{
var host = string.IsNullOrEmpty(appConfiguration.CurrentValue.FrontendBaseAddress)
@@ -471,7 +471,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(User)}.{nameof(RecoverPassword)}()");
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(21031.ToCodedError(localizer["Something went wrong."])));
}
}
@@ -494,7 +494,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(User)}.{nameof(IsValidRecoveryCode)}()");
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(21032.ToCodedError(localizer["Something went wrong."])));
}
}
@@ -503,7 +503,7 @@ namespace PrivaPub.Controllers.ClientToServer
{
var result = new WebResult();
if (!ModelState.IsValid)
return BadRequest(result.Invalidate(localizer["Invalid model."]));
return BadRequest(result.Invalidate(21033.ToCodedError(localizer["Invalid model."])));
try
{
result = await usersService.ChangePassword(newPasswordForm, token);
@@ -515,7 +515,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(User)}.{nameof(ChangePassword)}()");
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(21034.ToCodedError(localizer["Something went wrong."])));
}
}
@@ -524,7 +524,7 @@ namespace PrivaPub.Controllers.ClientToServer
{
var result = new WebResult();
if (!ModelState.IsValid)
return BadRequest(result.Invalidate(localizer["Invalid model."]));
return BadRequest(result.Invalidate(21035.ToCodedError(localizer["Invalid model."])));
try
{
result = await usersService.RemoveSelfAsync(User.GetUserId(), form.Password, token);
@@ -533,7 +533,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(User)}.{nameof(RemoveSelf)}()");
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(21036.ToCodedError(localizer["Something went wrong."])));
}
}
@@ -549,7 +549,7 @@ namespace PrivaPub.Controllers.ClientToServer
{
var user = await dbEntities.RootUsers.MatchID(User.GetUserId()).ExecuteFirstAsync(token);
if (user is not { IsBanned: false, DeletedAt: null })
return Unauthorized(result.Invalidate(localizer["Unauthorized."], StatusCodes.Status401Unauthorized));
return Unauthorized(result.Invalidate(21037.ToCodedError(localizer["Unauthorized."]), StatusCodes.Status401Unauthorized));
result = await usersService.GetUserSettingsAsync(user.ID, token: token);
if (!result.IsValid)
return StatusCode(result.StatusCode, result);
@@ -559,7 +559,7 @@ namespace PrivaPub.Controllers.ClientToServer
catch (Exception ex)
{
logger.LogError(ex, $"{nameof(User)}.{nameof(SniffAgain)}()");
return BadRequest(result.Invalidate(localizer["Something went wrong."]));
return BadRequest(result.Invalidate(21038.ToCodedError(localizer["Something went wrong."])));
}
}
@@ -29,7 +29,7 @@ namespace PrivaPub.Controllers.ClientToServer
public async Task<IActionResult> Following([FromQuery] string avatarId, CancellationToken token) =>
Answer(await follows.Followings(User.GetUserId(), avatarId, token));
IActionResult Invalid() => BadRequest(new WebResult().Invalidate(localizer["Invalid model."]));
IActionResult Invalid() => BadRequest(new WebResult().Invalidate(22001.ToCodedError(localizer["Invalid model."])));
IActionResult Answer(WebResult result) => result.IsValid ? Ok(result.Data) : StatusCode(result.StatusCode, result);
}