add error handler middleware
This commit is contained in:
parent
41e4dda7b4
commit
7a0247b551
13 changed files with 177 additions and 46 deletions
|
@ -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,
|
||||
}
|
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