add error handler middleware
This commit is contained in:
parent
41e4dda7b4
commit
7a0247b551
13 changed files with 177 additions and 46 deletions
28
Foxchat.Core/Models/Http/ApiError.cs
Normal file
28
Foxchat.Core/Models/Http/ApiError.cs
Normal 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,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue