Skip to content

JSON API: preserve valid sub-400 WP_Error statuses in serializable_error()#50173

Merged
darssen merged 1 commit into
trunkfrom
fix/json-api-serializable-error-preserve-valid-statuses
Jul 2, 2026
Merged

JSON API: preserve valid sub-400 WP_Error statuses in serializable_error()#50173
darssen merged 1 commit into
trunkfrom
fix/json-api-serializable-error-preserve-valid-statuses

Conversation

@darssen

@darssen darssen commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

PR #50077 hardened WPCOM_JSON_API::serializable_error() so that a WP_Error can no longer serialize a bogus status (the incident where an array without a status_code key cast to 1). That change did two things: it made the status extraction robust, and it also coerced every status below 400 up to 400.

The second part was too broad. Some callers return a WP_Error with a status below 400, for example a 302 redirect from the checkout flow, and a couple of older endpoints that return 100 or 200 with an error. Coercing those to 400 changed their behavior and started failing the Payments PayPal Express test suite.

This PR keeps the robust extraction from #50077 and narrows the default back to only handle a missing or invalid status. A value that is missing, non-numeric, or otherwise resolves to 0 still falls back to 400 (so the original incident stays fixed), but a valid HTTP status code, including one below 400, is now left as the caller set it.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No.

Testing instructions

  • Run the unit tests:
    jetpack docker phpunit jetpack -- --filter=WPCOM_JSON_API_Serializable_Error_Test
    
    14 tests pass. They cover the incident case (an array without status_code, a non-numeric value, and no data all default to 400), and that valid statuses, including 100, 200, and 302, pass through unchanged.

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the fix/json-api-serializable-error-preserve-valid-statuses branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/json-api-serializable-error-preserve-valid-statuses

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions Bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests labels Jul 2, 2026
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: July 7, 2026
    • Code freeze: July 6, 2026

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jul 2, 2026
@darssen darssen self-assigned this Jul 2, 2026
@darssen darssen added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Jul 2, 2026
@darssen darssen requested review from a team and martian77 July 2, 2026 13:33

@martian77 martian77 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Although I agree with the spirit of the original fix, the WP_Error code supports the other codes and has been used this way in WPCOM code so this is probably the correct way to guard against invalid responses.

Thanks for making this change! 🙇

@jp-launch-control

Copy link
Copy Markdown

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report · JS report

@darssen darssen merged commit ebb2d11 into trunk Jul 2, 2026
82 checks passed
@darssen darssen deleted the fix/json-api-serializable-error-preserve-valid-statuses branch July 2, 2026 13:49
@github-actions github-actions Bot added this to the jetpack/16.0 milestone Jul 2, 2026
@github-actions github-actions Bot removed the [Status] Needs Review This PR is ready for review. label Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants