From 26b7a82451561e0741be977ad428dbb79d6def41 Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 25 Mar 2026 10:26:24 +0100 Subject: [PATCH] Handle RecActionException in middleware with 422 response Added specific handling for RecActionException in the exception middleware. Now logs a warning with ActionId and ProfileId, returns a 422 Unprocessable Entity status, and provides detailed error information in the response. --- .../Middleware/ExceptionHandlingMiddleware.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/ReC.API/Middleware/ExceptionHandlingMiddleware.cs b/src/ReC.API/Middleware/ExceptionHandlingMiddleware.cs index 5ca3186..db5e5f0 100644 --- a/src/ReC.API/Middleware/ExceptionHandlingMiddleware.cs +++ b/src/ReC.API/Middleware/ExceptionHandlingMiddleware.cs @@ -164,6 +164,22 @@ public class ExceptionHandlingMiddleware }; break; + case RecActionException recActionEx: + logger.LogWarning( + recActionEx, + "Rec action failed. ActionId: {ActionId}, ProfileId: {ProfileId}", + recActionEx.ActionId, + recActionEx.ProfileId); + + context.Response.StatusCode = (int)HttpStatusCode.UnprocessableEntity; + details = new() + { + Title = "Rec Action Failed", + Detail = recActionEx.InnerException?.Message + ?? "An error occurred while executing the rec action. Check the logs for more details." + }; + break; + default: logger.LogError(exception, "Unhandled exception occurred."); context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;