Exceptions
Tree View
The following tree view describes how the Guzzle Exceptions depend on each other.
1. . \RuntimeException
2. └── TransferException (implements GuzzleException)
3. └── RequestException
4. ├── BadResponseException
5. │ ├── ServerException
6. │ └── ClientException
7. ├── ConnectException
8. └── 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\RequestExceptionis thrown. This exception extends fromGuzzleHttp\Exception\TransferException. Catching this exception will catch any exception that can be thrown while transferring requests.
``` 1. use GuzzleHttp\Psr7; 2. 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\ConnectExceptionexception is thrown in the event of a networking error. This exception extends fromGuzzleHttp\Exception\RequestException. - A
GuzzleHttp\Exception\ClientExceptionis thrown for 400 level errors if thehttp_errorsrequest option is set to true. This exception extends fromGuzzleHttp\Exception\BadResponseExceptionandGuzzleHttp\Exception\BadResponseExceptionextends fromGuzzleHttp\Exception\RequestException.
``` 1. use GuzzleHttp\Psr7; 2. 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\ServerExceptionis thrown for 500 level errors if thehttp_errorsrequest option is set to true. This exception extends fromGuzzleHttp\Exception\BadResponseException. - A
GuzzleHttp\Exception\TooManyRedirectsExceptionis thrown when too many redirects are followed. This exception extends fromGuzzleHttp\Exception\RequestException.
All of the above exceptions extend from GuzzleHttp\Exception\TransferException.
