Skip to content

Add request URL and method to error types#1187

Merged
jkmassel merged 3 commits intotrunkfrom
add/request-context-in-errors
Mar 2, 2026
Merged

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

Conversation

@jkmassel
Copy link
Copy Markdown
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 7 times, most recently 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
Copy Markdown
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.

Comment thread wp_api/src/middleware.rs Outdated
status_code: 200,
response_header_map: WpNetworkHeaderMap::default().into(),
request_url: WpEndpointUrl("http://example.com".to_string()),
request_method: RequestMethod::GET,
Copy link
Copy Markdown
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.

Comment thread wp_api/src/middleware.rs Outdated
error_message: "upload_media is not used".to_string(),
},
request_url: String::new(),
request_method: RequestMethod::POST,
Copy link
Copy Markdown
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.

Comment thread wp_mobile/src/service/posts.rs Outdated
error_message: "Network timeout".to_string(),
},
request_url: "https://test.local/wp-json".to_string(),
request_method: RequestMethod::GET,
Copy link
Copy Markdown
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.

jkmassel and others added 3 commits March 1, 2026 21:53
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 44cb12f to 23dd2da Compare March 2, 2026 04:53
@wpmobilebot
Copy link
Copy Markdown
Collaborator

XCFramework Build

This PR's XCFramework is available for testing. Add to your Package.swift:

.package(url: "https://github.com/automattic/wordpress-rs", branch: "pr-build/1187")

Built from 23dd2da

@jkmassel jkmassel merged commit a557060 into trunk Mar 2, 2026
33 checks passed
@jkmassel jkmassel deleted the add/request-context-in-errors branch March 2, 2026 05:46
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.

3 participants