[wp-trac] [WordPress Trac] #65421: AI Client: sendRequestWithOptions omits HTTP method from NetworkException message

WordPress Trac noreply at wordpress.org
Fri Jun 5 11:17:00 UTC 2026


#65421: AI Client: sendRequestWithOptions omits HTTP method from NetworkException
message
---------------------------+-----------------------------
 Reporter:  sagardeshmukh  |      Owner:  (none)
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  REST API       |    Version:  7.0
 Severity:  normal         |   Keywords:  has-patch
  Focuses:                 |
---------------------------+-----------------------------
 == Problem

 WP_AI_Client_HTTP_Client has two methods for sending HTTP requests:
 sendRequest() and sendRequestWithOptions(). When a WordPress HTTP error
 occurs, both throw a NetworkException - but their error messages are
 inconsistent.

 sendRequest() includes the HTTP method, URL, and underlying error:

   Network error occurred while sending POST request to https://…:
 Connection refused

 sendRequestWithOptions() omits the HTTP method:

   Network error occurred while sending request to https://…: Connection
 refused

 When debugging a failed AI request, the HTTP method is an important detail
 (e.g. knowing whether it was a GET or POST helps narrow down the issue).
 Both code paths should produce equivalent diagnostic messages.

 == Relevant code

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

 sendRequest() — line ~76:

   $message = sprintf(
       /* 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()
   );

 sendRequestWithOptions() — line ~107:

   $message = sprintf(
       /* translators: 1: Request URL. 2: Error message. */
       __( 'Network error occurred while sending request to %1$s: %2$s' ),
       $url,
       $response->get_error_message()
   );

 == Proposed fix

 Update sendRequestWithOptions() to match sendRequest()'s format:

   $message = sprintf(
       /* 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()
   );

 A test should also be added to assert the method, URL, and underlying
 error message all appear in the thrown NetworkException.

 == Introduced in

 This code was introduced in #64591.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/65421>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list