Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make error messages more detailed for exceptions thrown from Google Shipping Content service #2013

Open
4 tasks
eason9487 opened this issue Jul 13, 2023 · 0 comments
Labels
type: enhancement The issue is a request for an enhancement.

Comments

@eason9487
Copy link
Member

eason9487 commented Jul 13, 2023

This issue carries over the enhancement made for #1725 to follow up on the remaining places that could be enhanced consistently.

Context

Previously, #1258 has pointed out the way to unify GLA error messages for ApiException errors thrown from Google Ads APIs. In Google Shopping Content library, a thrown exception instance may be Google\Exception or Google\Service\Exception. The former simply extends Exception without adding anything.

In #2007, the handler for Google\Service\Exception has been added. It also adjusted the errors that may occur when connecting to a Google Merchant Center account. #2012 followed the same direction as #2007 to adjust the error handling for site verification methods.

Classes and methods related to Google Shipping Content library

Only listing the remaining ones

src/API/Google/Merchant.php

  • claimwebsite
  • get_accountstatus
  • has_access

src/API/Google/MerchantReport.php

  • get_report_data

Technical

There is another possible enhancement related to these changes. To create an ExceptionWithResponseData, the current code snippets are repeated many times. After evaluating the feasibility of de-duplicating these code snippets, the needed changes might be done together.

Example in ApiException catcher

$errors = $this->get_exception_errors( $e );
throw new ExceptionWithResponseData(
/* translators: %s Error message */
sprintf( __( 'Error retrieving campaigns: %s', 'google-listings-and-ads' ), reset( $errors ) ),
$this->map_grpc_code_to_http_status_code( $e ),
null,
[ 'errors' => $errors ]
);

Example in Google\Exception or Google\Service\Exception catcher

$errors = $this->get_exception_errors( $e );
throw new ExceptionWithResponseData(
/* translators: %s Error message */
sprintf( __( 'Unable to retrieve Merchant Center account: %s', 'google-listings-and-ads' ), reset( $errors ) ),
$e->getCode(),
null,
[ 'errors' => $errors ]
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

No branches or pull requests

1 participant