wppaste
WordPress

ClientException

Since
0.2.0
Source
wp-includes/php-ai-client/src/Providers/Http/Exception/ClientException.php:18
Exception thrown for 4xx HTTP client errors.

Description

This represents errors where the client request was malformed, unauthorized, forbidden, or otherwise invalid.

Compatibility

WordPress
since 0.2.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in 3 of the 5 tracked releases, added in 0.2.0.

Properties · 1

$requestWordPress\AiClient\Providers\Http\DTO\Request|nullprotected
The request that failed.

Methods · 2

Source code

class ClientException extends InvalidArgumentException{    /**     * The request that failed.     *     * @var Request|null     */    protected ?Request $request = null;    /**     * Returns the request that failed as our Request DTO.     *     * @since 0.2.0     *     * @return Request     * @throws \RuntimeException If no request is available     */    public function getRequest(): Request    {        if ($this->request === null) {            throw new \RuntimeException('Request object not available. This exception was directly instantiated. ' . 'Use a factory method that provides request context.');        }        return $this->request;    }    /**     * Creates a ClientException from a client error response (4xx).     *     * This method extracts error details from common API response formats     * and creates an exception with a descriptive message and status code.     *     * @since 0.2.0     *     * @param Response $response The HTTP response that failed.     * @return self     */    public static function fromClientErrorResponse(Response $response): self    {        $statusCode = $response->getStatusCode();        $statusTexts = [400 => 'Bad Request', 401 => 'Unauthorized', 403 => 'Forbidden', 404 => 'Not Found', 422 => 'Unprocessable Entity', 429 => 'Too Many Requests'];        if (isset($statusTexts[$statusCode])) {            $errorMessage = sprintf('%s (%d)', $statusTexts[$statusCode], $statusCode);        } else {            $errorMessage = sprintf('Client error (%d): Request was rejected due to client-side issue', $statusCode);        }        // Extract error message from response data using centralized utility        $extractedError = ErrorMessageExtractor::extractFromResponseData($response->getData());        if ($extractedError !== null) {            $errorMessage .= ' - ' . $extractedError;        }        return new self($errorMessage, $statusCode);    }}

Changelog

Introduced in 0.2.0. 2 changes between 6.9.7 and 7.1.0.

  1. 6.9.7
  2. 7.0.4
  3. 7.1.0

Signature, return type and hooks compared across 3 parsed releases.

7.0.4
Method getRequest() added.verified against source
7.0.4
Method fromClientErrorResponse() added.verified against source
0.2.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/php-ai-client/src/Providers/Http/Exception/ClientException.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.