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
@@ -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."])));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user