See Owin Frienly Exceptions for the owin middleware. This repository contains different framework plugins.
Installation:
Install-package OwinFriendlyExceptions.Plugins.WebApi2
Install-package OwinFriendlyExceptions.Plugins.WebApi2
app.UseFriendlyExceptions(exceptionsToHandle, new [] {new WebApi2ExceptionProvider()});
config.Services.Replace(typeof(IExceptionHandler), new WebApi2ExceptionHandler(exceptionsToHandle));
Install the package, and supply the WebApi Exception Provider to the OwinFriendlyExceptions extension method. In order for the Plugin to get swallowed exceptions you have to replace the ExcepionHandler service in Web Api. The plugin takes a list of which exceptions we can handle (that same collection fed to the middleware itself), so WebApi can still take care of unhandled exceptions for you.
When installing the Web Api Plugin, sometimes your System.Web.Http reference will mismatch. Use this Package Manager Console command to fix your Assembly Bining redirect: Get-Project YourProjectReferencingOwinFriendlyExceptions | Add-BindingRedirect
Contributions are welcome. Just open an Issue or submit a PR.
You can reach me at @bigCheeseAnders or via my blog: ideasof.andersaberg.com