If my Web API application is going to return an internal server error to a client, I want to know about it.
I want to set up something like ELMAH to notify me when the problem occurs, and I want full details of the error, including exception stack trace, logged on the server.
In MVC, the __Application_Error__ event is how you achive this, but in Web Api this event isn't triggered because exceptions are intentionally swallowed higher in the call stack. You can register an __ExceptionFilterAttribute__ to handle exceptions from action methods, but this won't handle other exceptions such as:
* Exceptions thrown by a message handler
* Exceptions thrown by a formatter
* Exceptions thrown when an IQueryable returned by an action method fails to execute
* Exceptions thrown due to routing errors
* Exceptions thrown when creating a controller instance
In a production environment, clients receive these errors with no information other than "An error has occurred" and no further information is available on server. It makes diagnosing problems reactive and difficult.
Please provide a global error handler for Web API so that error notifications can be sent and details logged.
I want to set up something like ELMAH to notify me when the problem occurs, and I want full details of the error, including exception stack trace, logged on the server.
In MVC, the __Application_Error__ event is how you achive this, but in Web Api this event isn't triggered because exceptions are intentionally swallowed higher in the call stack. You can register an __ExceptionFilterAttribute__ to handle exceptions from action methods, but this won't handle other exceptions such as:
* Exceptions thrown by a message handler
* Exceptions thrown by a formatter
* Exceptions thrown when an IQueryable returned by an action method fails to execute
* Exceptions thrown due to routing errors
* Exceptions thrown when creating a controller instance
In a production environment, clients receive these errors with no information other than "An error has occurred" and no further information is available on server. It makes diagnosing problems reactive and difficult.
Please provide a global error handler for Web API so that error notifications can be sent and details logged.