-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
44 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Microsoft.AspNetCore.Diagnostics; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace JixMinApi.Shared; | ||
|
||
internal sealed class GlobalExceptionHandler : IExceptionHandler | ||
{ | ||
private readonly ILogger<GlobalExceptionHandler> _logger; | ||
|
||
public GlobalExceptionHandler(ILogger<GlobalExceptionHandler> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public async ValueTask<bool> TryHandleAsync( | ||
HttpContext httpContext, | ||
Exception exception, | ||
CancellationToken cancellationToken) | ||
{ | ||
_logger.LogError( | ||
exception, "Exception occurred: {Message}", exception.Message); | ||
|
||
var problemDetails = new ProblemDetails | ||
{ | ||
Status = StatusCodes.Status500InternalServerError, | ||
Title = "Server error" | ||
}; | ||
|
||
httpContext.Response.StatusCode = problemDetails.Status.Value; | ||
|
||
await httpContext.Response | ||
.WriteAsJsonAsync(problemDetails, cancellationToken); | ||
|
||
return true; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.