J
J
Julia Kovalenko2016-08-17 16:49:22
Yii
Julia Kovalenko, 2016-08-17 16:49:22

How to catch Exception in php5.6 (guzzle5.3)?

I use guzzle to send requests.
Often I get responses with 403 or 404 codes.
I have it written like this

try {
...
} catch (\GuzzleHttp\Exception\RequestException $e) {
...
}

But this happens from time to time:
Exception 'GuzzleHttp\Exception\ConnectException' with message 'cURL error 35: Unknown SSL protocol error in connection to ... '

in .../vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:49

How can I catch all Guzzle exceptions with one try catch?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
shagguboy, 2016-08-17
@kovalenko_jul_s

absolutely nothing. interception of several exceptions appeared 7.1
crookedly possible like this

catch( Exception $e )
{
    if ($e instanceof \GuzzleHttp\Exception\RequestException OR $e instanceof GuzzleHttp\Exception\ConnectException) {

    } else {
       
        throw $e;
    }

M
Melkij, 2016-08-17
@melkij

https://github.com/guzzle/guzzle/blob/5.3/src/Exce...
ConnectException extends RequestException
catch (\GuzzleHttp\Exception\RequestException $e) will catch both exceptions. Check code and stacktrace. Perhaps you are looking at the wrong catch.

E
Evgeny Svirsky, 2016-08-17
@e_svirsky

And what's the problem with catching all exceptions like this:

try {
...
} catch (\Exception $e) {
...
}

Please catch all exceptions. And if you need specific ones, you can search through instanceof as indicated in the previous answer...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question