Error response for merchant center link/create operation.#3157
Error response for merchant center link/create operation.#3157ankitrox wants to merge 15 commits intofeature/GOOWOO-214-better-user-guidancefrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
mukeshpanchal27
left a comment
There was a problem hiding this comment.
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.
src/API/Google/Middleware.php
Outdated
| 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']; | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
This code is duplicated across the files. Please factor it out into a shared utility function.
| 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 | ||
| ); | ||
| } |
There was a problem hiding this comment.
Same as previous message
|
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. |
992f35c to
2e531ae
Compare
|
@mukeshpanchal27 Thanks for looking into it. |
mukeshpanchal27
left a comment
There was a problem hiding this comment.
Thanks for the update. It looks solid overall. I’ve left a few questions. Let me know if you need any clarification.
src/API/Google/Middleware.php
Outdated
| } | ||
| } | ||
| } | ||
| throw new Exception( $message, $status, $e ); |
There was a problem hiding this comment.
Why do we reference $e instead of $errors, considering $errors is derived from $e?
There was a problem hiding this comment.
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.
| $status = $e->getCode() ?: 400; | ||
| $error = is_array( $data ) ? ( $data['error'] ?? [] ) : []; | ||
| $message = is_array( $error ) && isset( $error['message'] ) ? (string) $error['message'] : $e->getMessage(); |
There was a problem hiding this comment.
This should be moved inside the if condition, since this variable only needs to be set when the error code is not API_ERROR.
There was a problem hiding this comment.
Thanks, nice observation. I updated it.
mukeshpanchal27
left a comment
There was a problem hiding this comment.
Thanks @ankitrox for the updates. The changes look good in my testing.
Make sure to merge develop branch so unit tests get passed.
…O-339-merchant-linking-error-response


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:
Detailed test instructions
You may need to checkout to
test/GOOWOO-214-integrationbranch to test these changes on FE. This feature branch is merged in the integration branch.Make sure test proxy is running.
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.
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