What is the proper way to implement a global Exception catcher-handler in a Katana (OWIN) implementation?
In a self-hosted OWIN/Katana implementation running as an A
Try this:
public class CustomExceptionHandler : IExceptionHandler
{
public Task HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken)
{
// Perform some form of logging
context.Result = new ResponseMessageResult(new HttpResponseMessage
{
Content = new StringContent("An unexpected error occurred"),
StatusCode = HttpStatusCode.InternalServerError
});
return Task.FromResult(0);
}
}
And at startup:
public void Configuration(IAppBuilder app)
{
var config = new HttpConfiguration();
config.Services.Replace(typeof(IExceptionHandler), new CustomExceptionHandler());
}