Hello all -
I am using Laravel 5.4 and am trying to customize exception/error handling a bit.
Right now, in the production environment, I explicitly catch TokenMismatchException and re-route the user back to login with an error message. Additionally, I catch the HTTP status codes 401, 403, 404 and 503, each of which has a custom error page attached to it.
What I would like to do with all other errors in production is go to a default/generic error page. However, when I try to implement this, it's also catching form validation errors and, instead of returning the user to the page where they made the error with the appropriate validation message, it redirects them to the default error page.
If I use the default return statement (as follows), validation on forms proceeds as expected, but if there is any other type of exception (other than a TokenMismatchException or an HTTP exception matching one of the above status codes), Laravel's "Whoops!" page is displayed (but without any details as to what the error is).
return parent::render($request, $exception);
Ideally, I would like to retain the expected validation behavior (i.e. returning the user to the page where the error was made with a message explaining what they did wrong), while capturing any other exceptions/errors and redirecting them to the default error page (instead of the Whoops page). As a bonus, I would like to be able to trigger an e-mail reporting the error to the developer (me) at the same time.
Exception handling is still pretty new territory for me so any thoughts/recommendations as to how I might be able to accomplish this would be much appreciated. Thank you!