Skip to content

Add request URL and method to error types#1187

Open
jkmassel wants to merge 3 commits intotrunkfrom
add/request-context-in-errors
Open

Add request URL and method to error types#1187
jkmassel wants to merge 3 commits intotrunkfrom
add/request-context-in-errors

Conversation

@jkmassel
Copy link
Contributor

@jkmassel jkmassel commented Feb 24, 2026

Summary

Error messages from the WordPress API are much more useful when they include which request failed. Previously, errors like RequestExecutionFailed or InvalidHttpStatusCode carried no information about the originating request, making it difficult to debug failures — especially when multiple requests are in flight.

  • Add request_url and request_method fields to WpApiError, RequestExecutionError, and WpNetworkResponse
  • RequestMethod is non-optional everywhere since errors always originate from a known HTTP request
  • Propagate the new fields through the Kotlin bindings (WpRequestResult, WpRequestExecutor, ApiClientHelpers)
  • Propagate the new fields through the Swift bindings (SafeRequestExecutor, Extensions, test helpers)
  • Fix pre-existing Swift LoginTests compilation error by updating from removed findLoginUrl(forSite:) to current details(ofSite:) API

Test plan

  • cargo test --lib passes (108 tests)
  • Android example app builds (./gradlew :example:composeApp:assembleDebug)
  • swift build succeeds
  • swift build --build-tests succeeds
  • Integration tests pass against test server

🤖 Generated with Claude Code

@jkmassel jkmassel force-pushed the add/request-context-in-errors branch from 9807ec5 to e3a0814 Compare February 24, 2026 22:43
@jkmassel jkmassel changed the base branch from add/wpcom-oauth to trunk February 24, 2026 22:43
@jkmassel jkmassel force-pushed the add/request-context-in-errors branch 6 times, most recently from 47291d5 to 77a9ba4 Compare February 25, 2026 23:53
jkmassel and others added 3 commits February 25, 2026 17:26
Add `request_url` and `request_method` fields to `WpApiError`,
`RequestExecutionError`, and `WpNetworkResponse` so error messages
include which request failed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Pass requestUrl and requestMethod to all error catch blocks in
executeRequestSafely and remove default parameter values to prevent
future regressions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jkmassel jkmassel force-pushed the add/request-context-in-errors branch from 77a9ba4 to 44cb12f Compare February 26, 2026 00:26
@jkmassel jkmassel marked this pull request as ready for review February 26, 2026 01:18
@jkmassel jkmassel requested a review from crazytonyli February 26, 2026 01:18
error_message: "Execute function is not necessary for these tests".to_string(),
},
request_url: String::new(),
request_method: RequestMethod::GET,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use the _request argument.

status_code: 200,
response_header_map: WpNetworkHeaderMap::default().into(),
request_url: WpEndpointUrl("http://example.com".to_string()),
request_method: RequestMethod::GET,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use the request argument.

error_message: "upload_media is not used".to_string(),
},
request_url: String::new(),
request_method: RequestMethod::POST,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use the _request argument.

error_message: "Network timeout".to_string(),
},
request_url: "https://test.local/wp-json".to_string(),
request_method: RequestMethod::GET,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use the request argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants