1- using System . Net ;
2- using Microsoft . AspNetCore . Mvc ;
1+ using Microsoft . AspNetCore . Mvc ;
32using Microsoft . AspNetCore . Mvc . Filters ;
43using Wax . Core . Exceptions ;
54
@@ -39,28 +38,12 @@ private void HandleBusinessException(ExceptionContext context)
3938 {
4039 _logger . Warning ( context . Exception . Message ) ;
4140
42- var problemDetails = new ValidationProblemDetails
43- {
44- Instance = context . HttpContext . Request . Path ,
45- Status = StatusCodes . Status400BadRequest ,
46- Detail = "Please refer to the errors property for additional details."
47- } ;
48-
49- problemDetails . Errors . Add ( "BusinessValidations" , new string [ ] { context . Exception . Message } ) ;
50-
51- context . Result = new BadRequestObjectResult ( problemDetails ) ;
52- context . HttpContext . Response . StatusCode = ( int ) HttpStatusCode . BadRequest ;
53- }
54-
55- private void HandleInternalServerError ( ExceptionContext context )
56- {
57- _logger . Error ( context . Exception , context . Exception . Message ) ;
58-
5941 var problemDetails = new ProblemDetails
6042 {
61- Status = StatusCodes . Status500InternalServerError ,
62- Title = "Internal error" ,
63- Detail = "An error occur.Try it again."
43+ Status = StatusCodes . Status403Forbidden ,
44+ Title = "Business error" ,
45+ Detail = context . Exception . Message ,
46+ Instance = context . HttpContext . Request . Path
6447 } ;
6548
6649 context . Result = new ObjectResult ( problemDetails ) ;
@@ -76,7 +59,7 @@ private void HandleEntityNotFoundException(ExceptionContext context)
7659 {
7760 Status = StatusCodes . Status404NotFound ,
7861 Title = "The specified resource was not found." ,
79- Detail = exception . Message
62+ Detail = exception . Message ,
8063 } ;
8164
8265 context . Result = new NotFoundObjectResult ( details ) ;
@@ -93,4 +76,18 @@ private void HandleValidationException(ExceptionContext context)
9376
9477 context . ExceptionHandled = true ;
9578 }
79+
80+ private void HandleInternalServerError ( ExceptionContext context )
81+ {
82+ _logger . Error ( context . Exception , context . Exception . Message ) ;
83+
84+ var problemDetails = new ProblemDetails
85+ {
86+ Status = StatusCodes . Status500InternalServerError ,
87+ Title = "Internal error" ,
88+ Detail = "An error occur.Try it again later."
89+ } ;
90+
91+ context . Result = new ObjectResult ( problemDetails ) ;
92+ }
9693}
0 commit comments