Make WordPress Core

Changeset 62753


Ignore:
Timestamp:
07/15/2026 08:28:05 AM (11 days ago)
Author:
gziolo
Message:

AI Client: Include the HTTP method in the sendRequestWithOptions() network error message.

WP_AI_Client_HTTP_Client::sendRequestWithOptions() omitted the HTTP method from its NetworkException message, while sendRequest() already included it. Both now use the same format, and a new test covers it.

Props sagarsdeshmukh, jorbin, gziolo.
Fixes #65421.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php

    r62255 r62753  
    105105                if ( is_wp_error( $response ) ) {
    106106                        $message = sprintf(
    107                                 /* translators: 1: Request URL. 2: Error message. */
    108                                 __( 'Network error occurred while sending request to %1$s: %2$s' ),
     107                                /* translators: 1: HTTP method (e.g. GET, POST). 2: Request URL. 3: Error message. */
     108                                __( 'Network error occurred while sending %1$s request to %2$s: %3$s' ),
     109                                $request->getMethod(),
    109110                                $url,
    110111                                $response->get_error_message()
  • trunk/tests/phpunit/tests/ai-client/wpAiClientHttpClient.php

    r61700 r62753  
    331331
    332332        /**
     333         * Test that sendRequestWithOptions includes the HTTP method in the NetworkException message.
     334         *
     335         * @ticket 65421
     336         */
     337        public function test_send_request_with_options_wp_error_message_includes_method() {
     338                add_filter(
     339                        'pre_http_request',
     340                        static function () {
     341                                return new WP_Error( 'http_request_failed', 'Connection refused' );
     342                        }
     343                );
     344
     345                $options = new WordPress\AiClient\Providers\Http\DTO\RequestOptions();
     346                $request = $this->psr17_factory->createRequest( 'POST', 'https://api.example.com/generate' );
     347
     348                try {
     349                        $this->client->sendRequestWithOptions( $request, $options );
     350                        $this->fail( 'Expected NetworkException was not thrown.' );
     351                } catch ( WordPress\AiClient\Providers\Http\Exception\NetworkException $e ) {
     352                        $this->assertStringContainsString( 'POST', $e->getMessage() );
     353                        $this->assertStringContainsString( 'https://api.example.com/generate', $e->getMessage() );
     354                        $this->assertStringContainsString( 'Connection refused', $e->getMessage() );
     355                }
     356        }
     357
     358        /**
    333359         * Test seekable body is rewound before sending.
    334360         *
Note: See TracChangeset for help on using the changeset viewer.