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

@ -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,
}