Skip to content

Latest commit

 

History

History
290 lines (112 loc) · 4.05 KB

BadResponseException.md

File metadata and controls

290 lines (112 loc) · 4.05 KB

BadResponseException

Exception when an HTTP error occurs (4xx or 5xx error)

Methods

__construct

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

hasResponse

Current exception and the ones that extend it will always have a response.

public hasResponse(): bool

getResponse

This function narrows the return type from the parent class and does not allow it to be nullable.

public getResponse(): \Psr\Http\Message\ResponseInterface

Inherited methods

__construct

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

wrapException

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

create

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

obfuscateUri

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

getRequest

Get the request that caused the exception

public getRequest(): \Psr\Http\Message\RequestInterface

getResponse

Get the associated response

public getResponse(): ?\Psr\Http\Message\ResponseInterface

hasResponse

Check if a response was received

public hasResponse(): bool

getHandlerContext

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.