I have created a global exception handler:
ServiceExceptionHandlers.Add((req, request, exception) =>
{
// log exception
Logger.Error(exception);
Logger.Info(req.OperationName + " - " + req.Headers["Device"] + "\n" + request.Dump());
// call default exception handler
return DtoUtils.CreateErrorResponse(request, exception);
});
If an exception happens the exception handler above fires as expected. DtoUtils.CreateErrorResponse
returns a proper object with a status code of 500 (which is correct) and this is correctly outputted to swagger or postman.
However when the service is marked with the [CacheResponse]
attribute and an exception happens, the status code in swagger/postman is now 200 and the error response has been cached.
How do I get the status code to be correct when using the Cache Response attribute and not have the error response cached?