-
Notifications
You must be signed in to change notification settings - Fork 1
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
Eduard Keilholz
committed
Jan 31, 2024
1 parent
29e8850
commit 2ab8d48
Showing
4 changed files
with
27 additions
and
32 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 was deleted.
Oops, something went wrong.
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.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
using Wam.Core.DataTransferObjects; | ||
using Wam.Core.Exceptions; | ||
|
||
namespace Wam.Core.Filters; | ||
|
||
public class WamExceptionFilter : IActionFilter, IOrderedFilter | ||
{ | ||
public int Order { get; } = int.MaxValue - 10; | ||
|
||
public void OnActionExecuting(ActionExecutingContext context) { } | ||
|
||
public void OnActionExecuted(ActionExecutedContext context) | ||
{ | ||
if (context.Exception is WamException exception) | ||
{ | ||
context.Result = new ObjectResult( | ||
new ExceptionDto(exception.Error.Code, exception.Error.TranslationKey.ToLower(), exception.Message)) | ||
{ | ||
StatusCode = 409 | ||
}; | ||
context.ExceptionHandled = true; | ||
} | ||
} | ||
} |