Hmmm ... I'd like to manage exceptions only in production.
Why ? In development, when an error occurs, built-in in Laravel, it's automatically displayed on the screen.
If I add custom exceptions, I won't have the standard error display on the screen, but my custom exception rendering. But this custom rendering if for the end users and not for me as developer.
What is the best way to customize the exceptions only in production ?
@tykus Thank you ... hmmm ... and what if I want to simply return to the page and only display an error message (flash message).
The problem is : the user triggers an action (it can simply be a post action). I don't want that the rendering is on the post route.
The best for me would be to redirect to the page (as it would be if the action was successful) and only display an error message on the screen for the end user (and also log the error message).
Sure I can return an error message directly from the redirection in the controller, but is there a way to do that from a custom Exception if needed ?
if you want to show the error in the page, you should catch the exception with try-catch and in the catch, show your message to your user and Log the error for your own review later.
Hmmm ... I'd like to manage exceptions only in production.
@vincent15000 Use the logging-related environment variables to dictate how and where log entries are written.
Usually, you write logs to the storage/logs/laravel.log file in local environments, and use something like Sentry to capture errors in a production environment. You’d achieve this by setting the LOG_CHANNEL environment to the appropriate value given the environment, i.e. LOG_CHANNEL=stack locally but LOG_CHANNEL=sentry in production. You don’t need custom code to handle exceptions differently for different environments.