fix: return correct error in GET /users/@me

This commit is contained in:
sam 2024-09-05 21:10:45 +02:00
parent 6c9d1c328b
commit 22d09ad7a6
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
5 changed files with 37 additions and 17 deletions

View file

@ -23,11 +23,15 @@ public class ApiError(string message, HttpStatusCode? statusCode = null, ErrorCo
public readonly HttpStatusCode StatusCode = statusCode ?? HttpStatusCode.InternalServerError;
public readonly ErrorCode ErrorCode = errorCode ?? ErrorCode.InternalServerError;
public class Unauthorized(string message) : ApiError(message, statusCode: HttpStatusCode.Unauthorized,
errorCode: ErrorCode.AuthenticationError);
public class Unauthorized(string message, ErrorCode errorCode = ErrorCode.AuthenticationError) : ApiError(message,
statusCode: HttpStatusCode.Unauthorized,
errorCode: errorCode);
public class Forbidden(string message, IEnumerable<string>? scopes = null)
: ApiError(message, statusCode: HttpStatusCode.Forbidden)
public class Forbidden(
string message,
IEnumerable<string>? scopes = null,
ErrorCode errorCode = ErrorCode.Forbidden)
: ApiError(message, statusCode: HttpStatusCode.Forbidden, errorCode: errorCode)
{
public readonly string[] Scopes = scopes?.ToArray() ?? [];
}
@ -115,6 +119,8 @@ public enum ErrorCode
Forbidden,
BadRequest,
AuthenticationError,
AuthenticationRequired,
MissingScopes,
GenericApiError,
UserNotFound,
MemberNotFound,