Skip to content

Error response for merchant center link/create operation.#3157

Open
ankitrox wants to merge 15 commits intofeature/GOOWOO-214-better-user-guidancefrom
add/GOOWOO-339-merchant-linking-error-response
Open

Error response for merchant center link/create operation.#3157
ankitrox wants to merge 15 commits intofeature/GOOWOO-214-better-user-guidancefrom
add/GOOWOO-339-merchant-linking-error-response

Conversation

@ankitrox
Copy link
Collaborator

@ankitrox ankitrox commented Nov 26, 2025

Changes proposed in this Pull Request:

Closes: https://linear.app/a8c/issue/GOOWOO-339/merchant-center-account-creationlinking-fails-insert-link

Replace this with a good description of your changes & reasoning.

Screenshots:

Screenshot 2025-12-12 at 10 57 12 PM

Detailed test instructions

You may need to checkout to test/GOOWOO-214-integration branch to test these changes on FE. This feature branch is merged in the integration branch.

  1. Make sure test proxy is running.

  2. Go to step 1 of the onboarding, make sure Jetpack and Google accounts are connected and Ads and MC cards are visible, but are not connected.

  3. Try connecting Ads and MC accounts one by one, the error would be displayed in corresponding cards as shown in screenshot.

Note: We also have corresponding E2E tests for these scenarios as well as for accounts auto-creation scenrio in integration branch given above.

Additional details:

Changelog entry

@github-actions github-actions bot added type: enhancement The issue is a request for an enhancement. changelog: add A new feature, function, or functionality was added. labels Nov 26, 2025
@codecov
Copy link

codecov bot commented Nov 26, 2025

Codecov Report

❌ Patch coverage is 41.26984% with 37 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.6%. Comparing base (c906f68) to head (110e124).
⚠️ Report is 71 commits behind head on feature/GOOWOO-214-better-user-guidance.

Files with missing lines Patch % Lines
src/MerchantCenter/AccountService.php 12.5% 14 Missing ⚠️
src/API/Google/Middleware.php 47.8% 12 Missing ⚠️
src/Ads/AccountService.php 8.3% 11 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                             Coverage Diff                              @@
##             feature/GOOWOO-214-better-user-guidance   #3157      +/-   ##
============================================================================
- Coverage                                       67.7%   66.6%    -1.1%     
- Complexity                                         0    5116    +5116     
============================================================================
  Files                                            359     869     +510     
  Lines                                           5835   26206   +20371     
  Branches                                        1446    1454       +8     
============================================================================
+ Hits                                            3950   17455   +13505     
- Misses                                          1711    8573    +6862     
- Partials                                         174     178       +4     
Flag Coverage Δ
js-unit-tests 67.5% <ø> (-0.2%) ⬇️
php-unit-tests 66.4% <41.3%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/API/Site/Controllers/Ads/AccountController.php 97.9% <ø> (ø)
...e/Controllers/MerchantCenter/AccountController.php 100.0% <100.0%> (ø)
src/Ads/AccountService.php 91.8% <8.3%> (ø)
src/API/Google/Middleware.php 89.8% <47.8%> (ø)
src/MerchantCenter/AccountService.php 88.8% <12.5%> (ø)

... and 503 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@asvinb asvinb changed the title Error reesponse for merchant center link/create operation. Error response for merchant center link/create operation. Dec 5, 2025
Copy link
Collaborator

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Could you please add testing instructions to the PR?

It would also be great if you include the Proxy testing: https://github.com/woocommerce/google-listings-and-ads/tree/develop/tests/proxy so we can test it easily.

Comment on lines +160 to +169
if ( $e instanceof BadResponseException ) {
$raw = json_decode( $e->getResponse()->getBody()->getContents(), true );
if ( is_array( $raw ) && ! empty( $raw['errors'] ) && is_array( $raw['errors'] ) ) {
foreach ( $raw['errors'] as $err ) {
if ( isset( $err['code'], $err['message'] ) ) {
$errors[ (string) $err['code'] ] = (string) $err['message'];
}
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This code is duplicated across the files. Please factor it out into a shared utility function.

Comment on lines +144 to +159
if ( $e->getPrevious() instanceof BadResponseException ) {
/** @var BadResponseException $prev */
$prev = $e->getPrevious();
$body = method_exists( $prev, 'getResponse' ) && $prev->getResponse() ? (string) $prev->getResponse()->getBody() : '';
$decoded = json_decode( $body, true );
$error = is_array( $decoded ) ? ( $decoded['error'] ?? [] ) : [];
$message = is_array( $error ) && isset( $error['message'] ) ? (string) $error['message'] : $e->getMessage();
throw $this->prepare_exception(
$message,
[
'code' => 'API_ERROR',
'error' => $error,
],
$e->getCode() ?: 400
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as previous message

@ankitrox
Copy link
Collaborator Author

Thank you @mukeshpanchal27 for reviewing the PR and adding the feedback.

I have updated the proxy to accommodate the changes and also updated the test instructions to test the PR changes.

Over to you for another review.

@ankitrox ankitrox force-pushed the add/GOOWOO-339-merchant-linking-error-response branch from 992f35c to 2e531ae Compare December 12, 2025 17:46
@mukeshpanchal27
Copy link
Collaborator

When i test this with proxy i get below errors:

Screenshot 2025-12-18 at 9 47 38 AM Screenshot 2025-12-18 at 9 48 29 AM

@ankitrox
Copy link
Collaborator Author

@mukeshpanchal27 Thanks for looking into it.
Can you please confirm if you are testing on the test/GOOWOO-214-integration branch?

Copy link
Collaborator

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

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

Thanks for the update. It looks solid overall. I’ve left a few questions. Let me know if you need any clarification.

}
}
}
throw new Exception( $message, $status, $e );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we reference $e instead of $errors, considering $errors is derived from $e?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can skip adding the error object completely. $errors can't be added as third parameter needs to be of type Throwable and $errors is array.

Comment on lines +177 to +179
$status = $e->getCode() ?: 400;
$error = is_array( $data ) ? ( $data['error'] ?? [] ) : [];
$message = is_array( $error ) && isset( $error['message'] ) ? (string) $error['message'] : $e->getMessage();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be moved inside the if condition, since this variable only needs to be set when the error code is not API_ERROR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, nice observation. I updated it.

Copy link
Collaborator

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

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

Thanks @ankitrox for the updates. The changes look good in my testing.

Make sure to merge develop branch so unit tests get passed.

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

Labels

changelog: add A new feature, function, or functionality was added. type: enhancement The issue is a request for an enhancement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants