You are here

public static function Middleware::httpErrors in Lockr 7.3

Middleware that throws exceptions for 4xx or 5xx responses when the "http_error" request option is set to true.

Return value

callable Returns a function that accepts the next handler.

1 call to Middleware::httpErrors()
HandlerStack::create in vendor/guzzlehttp/guzzle/src/HandlerStack.php
Creates a default handler stack that can be used by clients.

File

vendor/guzzlehttp/guzzle/src/Middleware.php, line 53

Class

Middleware
Functions used to create and wrap handlers with handler middleware.

Namespace

GuzzleHttp

Code

public static function httpErrors() {
  return function (callable $handler) {
    return function ($request, array $options) use ($handler) {
      if (empty($options['http_errors'])) {
        return $handler($request, $options);
      }
      return $handler($request, $options)
        ->then(function (ResponseInterface $response) use ($request, $handler) {
        $code = $response
          ->getStatusCode();
        if ($code < 400) {
          return $response;
        }
        throw RequestException::create($request, $response);
      });
    };
  };
}