'Redefine Exception from library in Laravel
I have question about redefining Exception from library. Just look into example:
We have a client library (in Laravel) for making API calls (for example, $this->client->request) in this library we have Exceptions\BadRequest.
What I need: to create handler which can catch Exception and make for example logs or sentry, whatever.
Right now I am doing try-catch for all client->request, but it is not ok, I need to make a handler.
Solution 1:[1]
Laravel has very good built in support for this. Look at the exception handling documentation: https://laravel.com/docs/9.x/errors#reporting-exceptions
You can register a new call back on exception messages to do what ever you have to. The global exception handler is located in: app/Exceptions/Handler.php
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vaugen Wakeling |
