From cbd86de3e8ecd25f3aba809fa4a28f1974c182a0 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Fri, 16 Jan 2026 01:10:57 +0100 Subject: [PATCH] Add handling for update and delete exceptions Enhanced `ExceptionHandlingMiddleware` to handle `UpdateObjectFailedException` and `DeleteObjectFailedException`. Logs exception details, including serialized procedure data, and sets HTTP status to `500 Internal Server Error`. Improves error differentiation and response for specific failure cases. --- .../Middleware/ExceptionHandlingMiddleware.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/ReC.API/Middleware/ExceptionHandlingMiddleware.cs b/src/ReC.API/Middleware/ExceptionHandlingMiddleware.cs index edb3684..478f18d 100644 --- a/src/ReC.API/Middleware/ExceptionHandlingMiddleware.cs +++ b/src/ReC.API/Middleware/ExceptionHandlingMiddleware.cs @@ -123,6 +123,40 @@ public class ExceptionHandlingMiddleware }; break; + case UpdateObjectFailedException updateFailedEx: + logger.LogError( + updateFailedEx, + "Update operation failed during request processing. {procedure}", + JsonSerializer.Serialize( + updateFailedEx.Procedure, + options: new() { WriteIndented = true } + )); + + context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; + details = new() + { + Title = "Update Operation Failed", + Detail = updateFailedEx.Message + }; + break; + + case DeleteObjectFailedException deleteFailedEx: + logger.LogError( + deleteFailedEx, + "Delete operation failed during request processing. {procedure}", + JsonSerializer.Serialize( + deleteFailedEx.Procedure, + options: new() { WriteIndented = true } + )); + + context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; + details = new() + { + Title = "Delete Operation Failed", + Detail = deleteFailedEx.Message + }; + break; + default: logger.LogError(exception, "Unhandled exception occurred."); context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;