in my PHP project, I use Guzzle to make a lot of different API requests. In order to handle all exception, each API call is wrapped into a try-catch block. An example:
Pass a callable, which can be an anonymous function, a regular function, or a class method:
function executeGuzzle(callable $fun) {
try {
return $fun();
} catch (ClientException $clientException) {
// Do stuff
} catch (ConnectException $connectException) {
// Do stuff
} catch (RequestException $requestException) {
// Do stuff
}
}
$res = executeGuzzle(function () use ($client) {
return $client->get(...);
});