For example, we have simple action method to show any book with proper id:
public ActionResult GetBook(int id) // id = 123456789
{
var book = dataManager.Books.GetBookById(id); // == null
logger.Info("Getting book with id " + book.Id);
return View(book);
}
If id
parameter is not valid we get 500 error because there is no book with that id.
We have to handle this situation manually if we need to throw 404 error, like this:
if (book == null)
{
return HttpNotFound();
}
Is it possible to switch 500-error to 404-error for all action methods somewhere in web-application (custom filter, request pipeline)?