Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guzzle Curl error not catche by try catch statement (Laravel)

In a Laravel project I need to call API REST to delete remote data.

My problem is that my catch statement dont catch Guzzle exception when I got an error. My code is the following :

try {
    $client = new \GuzzleHttp\Client();
    $request = $client->delete(Config::get('REST_API').'/order-product/'.$id);
    $status = $request->getStatusCode();
} catch (Exception $e) {
    var_dump($e);exit();
}

The exception is catched by Laravel but not in my catch statement. The exception throwed by Guzzle is :

GuzzleHttp\Ring\Exception\ConnectException

It raised in my line 3 of script and it doesn't catched in my script. Could you give me a way to catch the Guzzle Exception ?

I should indicate that I already seen these posts but I not get a good response : How to resolve cURL Error (7): couldn't connect to host? and Catching cURL errors from Guzzle

like image 488
Samuel Dauzon Avatar asked Aug 27 '15 14:08

Samuel Dauzon


1 Answers

It worked with me when I used

\GuzzleHttp\Exception\ConnectException

instead of

\Guzzle\Http\Exception\ConnectException

like image 89
Muhammad Avatar answered Sep 30 '22 04:09

Muhammad