Currently I have an ExceptionFilterAttribute to handle exceptions on controllers. My API connects to a service (via proprietary TCP/IP). If this service is not reachable I want to return a HTTP 504 response code with a proper error message.
I have figured out how to send a 400
public override void OnException(ExceptionContext context)
{
if (!MyService.IsConnected)
{
context.Result = new BadRequestObjectResult(new ResultInformation() { ResultCode = 2000056, Message = "My service is not reachable" });
}
else
{
context.Result = new BadRequestObjectResult(new ResultInformation() { ResultCode = 0, Message = context.Exception.Message });
}
}
How can I change this code to send a 504 and the error message?