feat(backend): improve bad request errors

This commit is contained in:
sam 2024-07-14 16:44:41 +02:00
parent e7ec0e6661
commit fb34464199
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
6 changed files with 114 additions and 45 deletions

View file

@ -47,7 +47,7 @@ public class AuthService(IClock clock, DatabaseContext db, ISnowflakeGenerator s
AssertValidAuthType(authType, instance);
if (await db.Users.AnyAsync(u => u.Username == username))
throw new ApiError.BadRequest("Username is already taken", "username");
throw new ApiError.BadRequest("Username is already taken", "username", username);
var user = new User
{
@ -124,7 +124,7 @@ public class AuthService(IClock clock, DatabaseContext db, ISnowflakeGenerator s
public (string, Token) GenerateToken(User user, Application application, string[] scopes, Instant expires)
{
if (!AuthUtils.ValidateScopes(application, scopes))
throw new ApiError.BadRequest("Invalid scopes requested for this token", "scopes");
throw new ApiError.BadRequest("Invalid scopes requested for this token", "scopes", scopes);
var (token, hash) = GenerateToken();
return (token, new Token