Exceptions
Tree View
The following tree view describes how the Guzzle Exceptions depend on each other.
. \RuntimeException
└── TransferException (implements GuzzleException)
└── RequestException
├── BadResponseException
│ ├── ServerException
│ └── ClientException
├── ConnectException
└── TooManyRedirectsException
Guzzle throws exceptions for errors that occur during a transfer.
In the event of a networking error (connection timeout, DNS errors, etc.), a
GuzzleHttp\Exception\RequestException
is thrown. This exception extends fromGuzzleHttp\Exception\TransferException
. Catching this exception will catch any exception that can be thrown while transferring requests.use GuzzleHttp\Psr7;
use GuzzleHttp\Exception\RequestException;
try {
$client->request('GET', 'https://github.com/_abc_123_404');
} catch (RequestException $e) {
echo Psr7\str($e->getRequest());
if ($e->hasResponse()) {
echo Psr7\str($e->getResponse());
}
}
A
GuzzleHttp\Exception\ConnectException
exception is thrown in the event of a networking error. This exception extends fromGuzzleHttp\Exception\RequestException
.A
GuzzleHttp\Exception\ClientException
is thrown for 400 level errors if thehttp_errors
request option is set to true. This exception extends fromGuzzleHttp\Exception\BadResponseException
andGuzzleHttp\Exception\BadResponseException
extends fromGuzzleHttp\Exception\RequestException
.use GuzzleHttp\Psr7;
use GuzzleHttp\Exception\ClientException;
try {
$client->request('GET', 'https://github.com/_abc_123_404');
} catch (ClientException $e) {
echo Psr7\str($e->getRequest());
echo Psr7\str($e->getResponse());
}
A
GuzzleHttp\Exception\ServerException
is thrown for 500 level errors if thehttp_errors
request option is set to true. This exception extends fromGuzzleHttp\Exception\BadResponseException
.A
GuzzleHttp\Exception\TooManyRedirectsException
is thrown when too many redirects are followed. This exception extends fromGuzzleHttp\Exception\RequestException
.
All of the above exceptions extend from GuzzleHttp\Exception\TransferException
.