Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ public function sendRequestWithOptions( RequestInterface $request, RequestOption

if ( is_wp_error( $response ) ) {
$message = sprintf(
/* translators: 1: Request URL. 2: Error message. */
__( 'Network error occurred while sending request to %1$s: %2$s' ),
/* translators: 1: HTTP method (e.g. GET, POST). 2: Request URL. 3: Error message. */
__( 'Network error occurred while sending %1$s request to %2$s: %3$s' ),
$request->getMethod(),
$url,
$response->get_error_message()
);
Expand Down
26 changes: 26 additions & 0 deletions tests/phpunit/tests/ai-client/wpAiClientHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,32 @@ static function () {
$this->client->sendRequestWithOptions( $request, $options );
}

/**
* Test that sendRequestWithOptions includes the HTTP method in the NetworkException message.
*
* @ticket 65421
*/
public function test_send_request_with_options_wp_error_message_includes_method() {
add_filter(
'pre_http_request',
static function () {
return new WP_Error( 'http_request_failed', 'Connection refused' );
}
);

$options = new WordPress\AiClient\Providers\Http\DTO\RequestOptions();
$request = $this->psr17_factory->createRequest( 'POST', 'https://api.example.com/generate' );

try {
$this->client->sendRequestWithOptions( $request, $options );
$this->fail( 'Expected NetworkException was not thrown.' );
} catch ( WordPress\AiClient\Providers\Http\Exception\NetworkException $e ) {
$this->assertStringContainsString( 'POST', $e->getMessage() );
$this->assertStringContainsString( 'https://api.example.com/generate', $e->getMessage() );
$this->assertStringContainsString( 'Connection refused', $e->getMessage() );
}
}

/**
* Test seekable body is rewound before sending.
*
Expand Down
Loading