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.
This commit is contained in:
@@ -123,6 +123,40 @@ public class ExceptionHandlingMiddleware
|
|||||||
};
|
};
|
||||||
break;
|
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:
|
default:
|
||||||
logger.LogError(exception, "Unhandled exception occurred.");
|
logger.LogError(exception, "Unhandled exception occurred.");
|
||||||
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
|
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
|
||||||
|
|||||||
Reference in New Issue
Block a user