I have a couple of custom exceptions in my business layer that bubble up to my API methods in my ASP.NET application.
Currently, they all translate to Http status 500. How do I map these custom exceptions so that I could return different Http status codes?
This is possible using Response.StatusCode setter and getter.
Local Exception handling: For local action exception handling, put the following inside the calling code.
For cross controller behavior: You should follow the below procedure.
BaseController.cs
Note:
You can also add the exception as handled and redirecting it into some other Controller/Action
More Information concerning ASP.NET MVC Error handling can be found HERE