Title: RedirectException::fromRedirectResponse
Published: May 20, 2026

---

# RedirectException::fromRedirectResponse( WordPressAiClientProvidersHttpDTOResponse $response ): self

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-redirectexception/fromredirectresponse/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-redirectexception/fromredirectresponse/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-redirectexception/fromredirectresponse/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-redirectexception/fromredirectresponse/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-redirectexception/fromredirectresponse/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-redirectexception/fromredirectresponse/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-redirectexception/fromredirectresponse/?output_format=md#wp--skip-link--target)

Creates a RedirectException from a redirect response.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-redirectexception/fromredirectresponse/?output_format=md#description)󠁿

This method extracts redirect information from the response headers and creates 
an exception with a descriptive message and status code.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-redirectexception/fromredirectresponse/?output_format=md#parameters)󠁿

 `$response`WordPressAiClientProvidersHttpDTOResponserequired

The HTTP redirect response.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-redirectexception/fromredirectresponse/?output_format=md#return)󠁿

 self

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-redirectexception/fromredirectresponse/?output_format=md#source)󠁿

    ```php
    public static function fromRedirectResponse(Response $response): self
    {
        $statusCode = $response->getStatusCode();
        $statusTexts = [300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 307 => 'Temporary Redirect', 308 => 'Permanent Redirect'];
        if (isset($statusTexts[$statusCode])) {
            $errorMessage = sprintf('%s (%d)', $statusTexts[$statusCode], $statusCode);
        } else {
            $errorMessage = sprintf('Redirect error (%d): Request needs to be retried at a different location', $statusCode);
        }
        // Try to extract the redirect location from headers
        $locationValues = $response->getHeader('Location');
        if ($locationValues !== null && !empty($locationValues)) {
            $location = $locationValues[0];
            $errorMessage .= ' - Location: ' . $location;
        }
        return new self($errorMessage, $statusCode);
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/php-ai-client/src/providers/http/exception/redirectexception.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/php-ai-client/src/Providers/Http/Exception/RedirectException.php#L30)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/php-ai-client/src/Providers/Http/Exception/RedirectException.php#L30-L46)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-redirectexception/fromredirectresponse/?output_format=md#related)󠁿

| Used by | Description | 
| [ResponseUtil::throwIfNotSuccessful()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-util-responseutil/throwifnotsuccessful/)`wp-includes/php-ai-client/src/Providers/Http/Util/ResponseUtil.php` |

Throws an appropriate exception if the given response is not successful.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-providers-http-exception-redirectexception/fromredirectresponse/?output_format=md#changelog)󠁿

| Version | Description | 
| [0.2.0](https://developer.wordpress.org/reference/since/0.2.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwordpress-aiclient-providers-http-exception-redirectexception%2Ffromredirectresponse%2F)
before being able to contribute a note or feedback.