Exception when an HTTP error occurs (4xx or 5xx error)
- Full name:
\GuzzleHttp\Exception\BadResponseException
- Parent class:
\GuzzleHttp\Exception\RequestException
public __construct(string $message, \Psr\Http\Message\RequestInterface $request, \Psr\Http\Message\ResponseInterface $response, \Throwable $previous = null, array $handlerContext = []): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$message |
string | |
$request |
\Psr\Http\Message\RequestInterface | |
$response |
\Psr\Http\Message\ResponseInterface | |
$previous |
\Throwable | |
$handlerContext |
array |
Current exception and the ones that extend it will always have a response.
public hasResponse(): bool
This function narrows the return type from the parent class and does not allow it to be nullable.
public getResponse(): \Psr\Http\Message\ResponseInterface
public __construct(string $message, \Psr\Http\Message\RequestInterface $request, \Psr\Http\Message\ResponseInterface $response = null, \Throwable $previous = null, array $handlerContext = []): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$message |
string | |
$request |
\Psr\Http\Message\RequestInterface | |
$response |
\Psr\Http\Message\ResponseInterface | |
$previous |
\Throwable | |
$handlerContext |
array |
Wrap non-RequestExceptions with a RequestException
public static wrapException(\Psr\Http\Message\RequestInterface $request, \Throwable $e): \GuzzleHttp\Exception\RequestException
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$request |
\Psr\Http\Message\RequestInterface | |
$e |
\Throwable |
Factory method to create a new exception with a normalized error message
public static create(\Psr\Http\Message\RequestInterface $request, \Psr\Http\Message\ResponseInterface $response = null, \Throwable|null $previous = null, array $handlerContext = [], \GuzzleHttp\BodySummarizerInterface|null $bodySummarizer = null): self
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$request |
\Psr\Http\Message\RequestInterface | Request sent |
$response |
\Psr\Http\Message\ResponseInterface | Response received |
$previous |
\Throwable|null | Previous exception |
$handlerContext |
array | Optional handler context |
$bodySummarizer |
\GuzzleHttp\BodySummarizerInterface|null | Optional body summarizer |
Obfuscates URI if there is a username and a password present
private static obfuscateUri(\Psr\Http\Message\UriInterface $uri): \Psr\Http\Message\UriInterface
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$uri |
\Psr\Http\Message\UriInterface |
Get the request that caused the exception
public getRequest(): \Psr\Http\Message\RequestInterface
Get the associated response
public getResponse(): ?\Psr\Http\Message\ResponseInterface
Check if a response was received
public hasResponse(): bool
Get contextual information about the error from the underlying handler.
public getHandlerContext(): array
The contents of this array will vary depending on which handler you are using. It may also be just an empty array. Relying on this data will couple you to a specific handler, but can give more debug information when needed.