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.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user