mirror of
https://github.com/azaion/admin.git
synced 2026-04-22 09:06:33 +00:00
[AZ-199] [AZ-200] [AZ-201] [AZ-202] Fix API bugs
Made-with: Cursor
This commit is contained in:
@@ -10,19 +10,36 @@ public class BusinessExceptionHandler(ILogger<BusinessExceptionHandler> logger)
|
||||
{
|
||||
public async ValueTask<bool> TryHandleAsync(HttpContext httpContext, Exception exception, CancellationToken cancellationToken)
|
||||
{
|
||||
if (exception is not BusinessException ex)
|
||||
return false;
|
||||
|
||||
logger.LogWarning(exception, ex.Message);
|
||||
httpContext.Response.StatusCode = StatusCodes.Status409Conflict;
|
||||
httpContext.Response.ContentType = "application/json";
|
||||
|
||||
var err = JsonConvert.SerializeObject(new
|
||||
if (exception is BusinessException ex)
|
||||
{
|
||||
ErrorCode = ex.ExceptionEnum,
|
||||
ex.Message
|
||||
});
|
||||
await httpContext.Response.WriteAsync(err, cancellationToken).ConfigureAwait(false);
|
||||
return true;
|
||||
logger.LogWarning(exception, ex.Message);
|
||||
httpContext.Response.StatusCode = StatusCodes.Status409Conflict;
|
||||
httpContext.Response.ContentType = "application/json";
|
||||
|
||||
var err = JsonConvert.SerializeObject(new
|
||||
{
|
||||
ErrorCode = ex.ExceptionEnum,
|
||||
ex.Message
|
||||
});
|
||||
await httpContext.Response.WriteAsync(err, cancellationToken).ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (exception is BadHttpRequestException badReq)
|
||||
{
|
||||
logger.LogWarning(exception, badReq.Message);
|
||||
httpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
|
||||
httpContext.Response.ContentType = "application/json";
|
||||
|
||||
var err = JsonConvert.SerializeObject(new
|
||||
{
|
||||
ErrorCode = 0,
|
||||
badReq.Message
|
||||
});
|
||||
await httpContext.Response.WriteAsync(err, cancellationToken).ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user