Skip to content

[WOOMOB-54] Handle empty REST API namespaces during site login - #16408

Open
JorgeMucientes wants to merge 2 commits into
trunkfrom
woomob-54-show-generic-error-when-fetching-site-urlwp-json-namespaces
Open

[WOOMOB-54] Handle empty REST API namespaces during site login#16408
JorgeMucientes wants to merge 2 commits into
trunkfrom
woomob-54-show-generic-error-when-fetching-site-urlwp-json-namespaces

Conversation

@JorgeMucientes

@JorgeMucientes JorgeMucientes commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes WOOMOB-54

When the WordPress REST API root response contains no namespaces, site-credentials login currently treats it as a valid non-WooCommerce site and can continue into misleading fallback UI. This change treats an absent or empty namespaces field as an invalid response so the existing generic site-fetch error is shown instead. Responses with populated namespaces keep their existing behavior.

Test Steps

  1. On a disposable WooCommerce test site, install and activate the Code Snippets plugin.
  2. Go to Snippets > Add New, name the snippet Hide REST API namespaces, and add this code (without a <?php opening tag):
    add_filter( 'rest_index', function ( WP_REST_Response $response ) {
        $data = $response->get_data();
        $data['namespaces'] = array();
        $response->set_data( $data );
        return $response;
    } );
  3. Select Run snippet everywhere, then save and activate the snippet.
  4. Open https://YOUR-SITE/wp-json?_fields=namespaces and confirm the response contains "namespaces":[].
  5. Start the app logged out and log in using site credentials flow (NOT WP.com)
  6. Verify the app shows An error occurred while fetching your website. It must not open the Application Password authorization/tutorial flow or show the non-WooCommerce error.
  7. Deactivate the snippet, repeat the login, and verify the normal site-credentials login flow resumes.

Images/gif

  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

@JorgeMucientes JorgeMucientes added type: bug A confirmed bug. feature: login Related to any part of the log in or sign in flow, or authentication. labels Aug 12, 2026
@JorgeMucientes JorgeMucientes added this to the 25.5 milestone Aug 12, 2026
@wpmobilebot

Copy link
Copy Markdown
Collaborator

App Icon📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App NameWooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Build Number778
Version25.4-rc-1
Application IDcom.woocommerce.android.prealpha
Commitd0970b1
Installation URL2qhhhbrrelc38
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@JorgeMucientes
JorgeMucientes marked this pull request as ready for review August 12, 2026 15:06

@claude claude Bot 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.

AI Code Review - No issues found. The changes look good.

The new guard returns an INVALID_RESPONSE error when a site's REST API exposes no namespaces, which cleanly prevents the login flow from proceeding into misleading setup screens. A couple of things I verified:

  • The non-null accesses after the guard (response.name, response.namespaces.any { ... }) compile correctly because isNullOrEmpty()'s Kotlin contract smart-casts both response and response.namespaces to non-null on the fall-through path.
  • The error propagates as expected: updateSite maps it via SiteErrorUtils.genericToSiteError, and WPApiSiteRepository.fetchSite logs and surfaces it as a failure.
  • The behavior change is deliberate and release-noted; a site that previously "succeeded" with empty namespaces could not be verified as WooCommerce anyway, so erroring is the correct outcome.
  • Test coverage is solid: empty namespaces, null namespaces, and non-empty-without-WooCommerce are all exercised.

Automatic review · claude-opus-4-8 · Workflow run

How to reply to a finding

Reply on this review (or inline at the line the finding refers to) with one of:

  • @claude addressed - I made the change. Bot verifies against the next diff before marking resolved.
  • @claude rejected: <reason> - Will not fix; reason gets quoted on the next review.
  • @claude not-applicable - Finding does not apply (wrong file, already covered elsewhere, etc.).

The bot honours these on the next review pass.

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

Labels

feature: login Related to any part of the log in or sign in flow, or authentication. type: bug A confirmed bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants