[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/guzzlehttp/guzzle/src/Subscriber/ -> HttpError.php (source)

   1  <?php
   2  namespace GuzzleHttp\Subscriber;
   3  
   4  use GuzzleHttp\Event\CompleteEvent;
   5  use GuzzleHttp\Event\RequestEvents;
   6  use GuzzleHttp\Event\SubscriberInterface;
   7  use GuzzleHttp\Exception\RequestException;
   8  
   9  /**
  10   * Throws exceptions when a 4xx or 5xx response is received
  11   */
  12  class HttpError implements SubscriberInterface
  13  {
  14      public function getEvents()
  15      {
  16          return ['complete' => ['onComplete', RequestEvents::VERIFY_RESPONSE]];
  17      }
  18  
  19      /**
  20       * Throw a RequestException on an HTTP protocol error
  21       *
  22       * @param CompleteEvent $event Emitted event
  23       * @throws RequestException
  24       */
  25      public function onComplete(CompleteEvent $event)
  26      {
  27          $code = (string) $event->getResponse()->getStatusCode();
  28          // Throw an exception for an unsuccessful response
  29          if ($code[0] >= 4) {
  30              throw RequestException::create(
  31                  $event->getRequest(),
  32                  $event->getResponse()
  33              );
  34          }
  35      }
  36  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1