php - Symfony handling errors
Is it somehow possible, if you use e.g. get or set from an entity or also when saving with doctrine and there is an error, to return false?
At the moment there is always an error e.g. 500. I would like to intercept this and return false. How is that best possible?
Answer
Solution:
You can create your own Event Listener for exceptions and based upon exception type convert it to Response. For example you can add some message into flesh bag and then redirect user to the previous route.
Please find more info in official documentation: https://symfony.com/doc/current/event_dispatcher.html#creating-an-event-listener
Source