From 02b509711bcb9ac1ef74d49b83f4211f6482c535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Michel?= Date: Fri, 21 Jan 2022 16:07:11 +0100 Subject: [PATCH] Feature/exception response (#663) * return 500 code for other exception with json response * not throw --- src/PublicApi/Middleware/ExceptionMiddleware.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/PublicApi/Middleware/ExceptionMiddleware.cs b/src/PublicApi/Middleware/ExceptionMiddleware.cs index 46b24f8..ebd19a5 100644 --- a/src/PublicApi/Middleware/ExceptionMiddleware.cs +++ b/src/PublicApi/Middleware/ExceptionMiddleware.cs @@ -24,7 +24,7 @@ public class ExceptionMiddleware } catch (Exception ex) { - await HandleExceptionAsync(httpContext, ex); + await HandleExceptionAsync(httpContext, ex); } } @@ -41,5 +41,12 @@ public class ExceptionMiddleware Message = duplicationException.Message }.ToString()); } + + context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; + await context.Response.WriteAsync(new ErrorDetails() + { + StatusCode = context.Response.StatusCode, + Message = exception.Message + }.ToString()); } }