Skip to content

Commit 266e997

Browse files
authored
Merge branch 'WordPress:trunk' into trunk
2 parents a7bbea0 + 16af489 commit 266e997

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

src/wp-includes/ai-client/adapters/class-wp-ai-client-http-client.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ public function sendRequestWithOptions( RequestInterface $request, RequestOption
104104

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()
111112
);

tests/phpunit/tests/ai-client/wpAiClientHttpClient.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,32 @@ static function () {
329329
$this->client->sendRequestWithOptions( $request, $options );
330330
}
331331

332+
/**
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+
332358
/**
333359
* Test seekable body is rewound before sending.
334360
*

0 commit comments

Comments
 (0)