add error handler middleware

This commit is contained in:
sam 2024-05-20 19:42:04 +02:00
parent 41e4dda7b4
commit 7a0247b551
13 changed files with 177 additions and 46 deletions

View file

@ -1,17 +0,0 @@
namespace Foxchat.Core.Models;
public record ApiError(int Status, ErrorCode Code, string Message);
public enum ErrorCode
{
INTERNAL_SERVER_ERROR,
OBJECT_NOT_FOUND,
INVALID_SERVER,
INVALID_HEADER,
INVALID_DATE,
INVALID_SIGNATURE,
MISSING_SIGNATURE,
GUILD_NOT_FOUND,
UNAUTHORIZED,
INVALID_REST_EVENT,
}

View file

@ -0,0 +1,28 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace Foxchat.Core.Models.Http;
public record ApiError
{
public required int Status { get; init; }
[JsonConverter(typeof(StringEnumConverter))]
public required ErrorCode Code { get; init; }
public required string Message { get; init; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public ApiError? OriginalError { get; init; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string[]? Scopes { get; init; }
}
public enum ErrorCode
{
InternalServerError,
Unauthorized,
Forbidden,
BadRequest,
OutgoingFederationError,
AuthenticationError,
// TODO: more specific API error codes
GenericApiError,
}