From f4b578c20294d930f94a4f827082736992e9045e Mon Sep 17 00:00:00 2001 From: gumbarros Date: Wed, 8 Jan 2025 14:45:57 -0300 Subject: [PATCH 1/2] Add logger to WebApi Error Controller --- src/WebApi/Controllers/ErrorController.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/WebApi/Controllers/ErrorController.cs b/src/WebApi/Controllers/ErrorController.cs index 509d66ff1..c4ecb02af 100644 --- a/src/WebApi/Controllers/ErrorController.cs +++ b/src/WebApi/Controllers/ErrorController.cs @@ -6,7 +6,7 @@ namespace JJMasterData.WebApi.Controllers; [ApiController] [ApiExplorerSettings(IgnoreApi = true)] -public class ErrorController : ControllerBase +public class ErrorController(ILogger logger) : ControllerBase { [Route("/Error")] public IActionResult HandleError() @@ -14,8 +14,12 @@ public IActionResult HandleError() var exceptionHandlerFeature = HttpContext.Features.Get()!; - var responseLetter = ExceptionManager.GetResponse(exceptionHandlerFeature.Error); + var error = exceptionHandlerFeature.Error; + + var responseLetter = ExceptionManager.GetResponse(error); + logger.LogCritical(error, "Unexpected error at WebApi."); + return new ObjectResult(responseLetter) { StatusCode = responseLetter.Status From ec8d7c3c3cb7222ad63b35bf31f88272cc5b416e Mon Sep 17 00:00:00 2001 From: gumbarros Date: Wed, 8 Jan 2025 14:50:03 -0300 Subject: [PATCH 2/2] Add missing to Api --- src/WebApi/WebApi.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/WebApi/WebApi.csproj b/src/WebApi/WebApi.csproj index 5edc2c624..ff674e143 100644 --- a/src/WebApi/WebApi.csproj +++ b/src/WebApi/WebApi.csproj @@ -11,6 +11,7 @@ JJMasterData.WebApi true JJMasterData.WebApi + JJMasterData.WebApi true library false