public static function Middleware::httpErrors in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/guzzlehttp/guzzle/src/Middleware.php \GuzzleHttp\Middleware::httpErrors()
 
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 54  
Class
- Middleware
 - Functions used to create and wrap handlers with handler middleware.
 
Namespace
GuzzleHttpCode
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 $code > 499 ? new ServerException("Server error: {$code}", $request, $response) : new ClientException("Client error: {$code}", $request, $response);
      });
    };
  };
}