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;
    3. try {
    4. $client->request('GET', 'https://github.com/_abc_123_404');
    5. } catch (RequestException $e) {
    6. echo Psr7\str($e->getRequest());
    7. if ($e->hasResponse()) {
    8. echo Psr7\str($e->getResponse());
    9. }
    10. }
  • A GuzzleHttp\Exception\ConnectException exception is thrown in the event of a networking error. This exception extends from GuzzleHttp\Exception\RequestException.

  • 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;
    3. try {
    4. $client->request('GET', 'https://github.com/_abc_123_404');
    5. } catch (ClientException $e) {
    6. echo Psr7\str($e->getRequest());
    7. echo Psr7\str($e->getResponse());
    8. }
  • 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.

  • 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.