-
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.
Add IExceptionHandler in shared to be used in all services
- Loading branch information
1 parent
6dc86a6
commit 00e0cd1
Showing
3 changed files
with
34 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
namespace shared; | ||
using Microsoft.AspNetCore.Diagnostics; | ||
|
||
public class Class1 | ||
{ | ||
namespace shared; | ||
|
||
public class Class1 | ||
{ | ||
|
||
} |
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,26 @@ | ||
using Microsoft.AspNetCore.Diagnostics; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace ErrorHandler; | ||
|
||
|
||
/* Handle Exceptions in a centralized way */ | ||
|
||
public class CustomExceptionHandler : IExceptionHandler | ||
{ | ||
public async ValueTask<bool> TryHandleAsync(HttpContext httpContext, Exception exception, CancellationToken cancellationToken) | ||
{ | ||
var exceptionMessage = exception.Message; | ||
|
||
var problemDetails = new ProblemDetails{ | ||
Title = "An Error has occured", | ||
Detail = exceptionMessage | ||
}; | ||
|
||
await httpContext.Response.WriteAsJsonAsync(problemDetails, cancellationToken); | ||
|
||
|
||
return true; | ||
} | ||
} |
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