Exceptions

Tree View

The following tree view describes how the Guzzle Exceptions depend on each other.

1. . \RuntimeException
2. ├── SeekException (implements GuzzleException)
3. └── TransferException (implements GuzzleException)
4. └── RequestException
5. ├── BadResponseException
6. │   ├── ServerException
7. │   └── ClientException
8. ├── ConnectException
9. └── 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 from GuzzleHttp\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;

  1. try {
  2. $client->request('GET', 'https://github.com/_abc_123_404');
  3. } catch (RequestException $e) {
  4. echo Psr7\str($e->getRequest());
  5. if ($e->hasResponse()) {
  6. echo Psr7\str($e->getResponse());
  7. }
  8. } ```
  9. A GuzzleHttp\Exception\ConnectException exception is thrown in the event of a networking error. This exception extends from GuzzleHttp\Exception\RequestException.
  10. A GuzzleHttp\Exception\ClientException is thrown for 400 level errors if the http_errors request option is set to true. This exception extends from GuzzleHttp\Exception\BadResponseException and GuzzleHttp\Exception\BadResponseException extends from GuzzleHttp\Exception\RequestException.

``` 1. use GuzzleHttp\Psr7; 2. use GuzzleHttp\Exception\ClientException;

  1. try {
  2. $client->request('GET', 'https://github.com/_abc_123_404');
  3. } catch (ClientException $e) {
  4. echo Psr7\str($e->getRequest());
  5. echo Psr7\str($e->getResponse());
  6. } ```
  7. A GuzzleHttp\Exception\ServerException is thrown for 500 level errors if the http_errors request option is set to true. This exception extends from GuzzleHttp\Exception\BadResponseException.
  8. A GuzzleHttp\Exception\TooManyRedirectsException is thrown when too many redirects are followed. This exception extends from GuzzleHttp\Exception\RequestException.

All of the above exceptions extend from GuzzleHttp\Exception\TransferException.