แก้บั้ก Global Exception Middleware

This commit is contained in:
Suphonchai Phoonsawat 2023-07-13 15:54:29 +07:00
parent b99d7e759b
commit 01c55f296d
3 changed files with 6 additions and 3 deletions

View file

@ -31,18 +31,20 @@ namespace BMA.EHR.Domain.Middlewares
await _next(context);
var response = context.Response;
response.ContentType = "application/json";
var responseModel = new ResponseObject();
responseModel.Status = response.StatusCode;
if (responseModel.Status == (int)HttpStatusCode.Unauthorized)
{
response.ContentType = "application/json";
responseModel.Message = GlobalMessages.NotAuthorized;
await response.WriteAsJsonAsync(responseModel);
}
if (responseModel.Status == (int)HttpStatusCode.Forbidden)
{
response.ContentType = "application/json";
responseModel.Message = GlobalMessages.ForbiddenAccess;
await response.WriteAsJsonAsync(responseModel);
}