function Middleware::httpErrors
Middleware that throws exceptions for 4xx or 5xx responses when the "http_errors" request option is set to true.
Parameters
BodySummarizerInterface|null $bodySummarizer The body summarizer to use in exception messages.:
Return value
callable(callable): 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 58
Class
- Middleware
- Functions used to create and wrap handlers with handler middleware.
Namespace
GuzzleHttpCode
public static function httpErrors(?BodySummarizerInterface $bodySummarizer = null) : callable {
return static function (callable $handler) use ($bodySummarizer) : callable {
return static function ($request, array $options) use ($handler, $bodySummarizer) {
if (empty($options['http_errors'])) {
return $handler($request, $options);
}
return $handler($request, $options)->then(static function (ResponseInterface $response) use ($request, $bodySummarizer) {
$code = $response->getStatusCode();
if ($code < 400) {
return $response;
}
throw RequestException::create($request, $response, null, [], $bodySummarizer);
});
};
};
}