Skip to content

feat: Handle Google Ads EU Political Advertising Declaration error #747

Open
Itzaprado wants to merge 2 commits into
looker-open-source:masterfrom
Itzaprado:itzaprado/gads-eu-political-ad-error
Open

feat: Handle Google Ads EU Political Advertising Declaration error #747
Itzaprado wants to merge 2 commits into
looker-open-source:masterfrom
Itzaprado:itzaprado/gads-eu-political-ad-error

Conversation

@Itzaprado
Copy link
Copy Markdown
Collaborator

Description

This PR implements user-friendly error handling for the Google Ads API error EU_POLITICAL_ADVERTISING_DECLARATION_REQUIRED.

According to Google Ads API Policy, advertisers who wish to show political ads in the EU must complete identity verification and declare their intent in the Google Ads UI. If they attempt to use Customer Match without doing so, the API returns this specific error.

Instead of displaying a generic "Request contains an invalid argument" error, this change intercepts the error and provides actionable guidance to the user, redirecting them to the verification steps.

Technical Changes

  • Async Fix: Fixed a bug in GoogleAdsApiClient where apiCall promises were not being awaited within the try/catch block, causing API errors to bypass the local error handler.
  • Error Preservation: Updated the client to tag the intercepted error as "EU Political Advertising Error".
  • Global Handler Update: Modified makeBetterErrorMessage in error_utils.ts to recognize this tagged error and return early, preventing the custom message from being overwritten by generic API error details.
  • Tests: Added a unit test in test_customer_match.ts that mocks this API error and verifies the end-to-end integration and the final error message structure.

Reference Documentation

Itzaprado added 2 commits May 12, 2026 21:46
- Fix async bug in GoogleAdsApiClient where apiCall was not awaited in try-catch, causing errors to bypass handleEuPoliticalError.
- Fix error overwrite bug in makeBetterErrorMessage where customized error messages were lost.
- Add test case in test_customer_match.ts to verify the EU political ad error handling flow.

TAG=agy
@Itzaprado Itzaprado requested a review from a team as a code owner May 25, 2026 23:41
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces custom error handling for the Google Ads API error EU_POLITICAL_ADVERTISING_DECLARATION_REQUIRED, providing a clear, actionable error message for EU political advertising requirements. It also updates error utilities to append webhook IDs to this error and adds corresponding unit tests. The review feedback suggests centralizing the error handling logic inside the apiCall method to avoid duplicating try/catch blocks across multiple API methods, and using optional chaining when checking the error name in makeBetterErrorMessage to prevent potential runtime errors.

Comment on lines +84 to +89
try {
return await this.apiCall(method, path, body)
} catch (error) {
this.handleEuPoliticalError(error)
throw error
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Instead of duplicating the try/catch block and handleEuPoliticalError call in every API method (like createUserList and createDataJob), it is much cleaner and more maintainable to centralize this error handling inside the apiCall method itself. This avoids code duplication and ensures that all API calls (including addDataJobOperations, runJob, and any future methods) automatically benefit from the EU political advertising error interceptor.

      return this.apiCall(method, path, body)

Comment on lines +116 to +121
try {
return await this.apiCall(method, path, body)
} catch (error) {
this.handleEuPoliticalError(error)
throw error
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Centralizing the error handling inside the apiCall method itself is recommended to avoid code duplication across multiple API methods.

      return this.apiCall(method, path, body)

Comment on lines +31 to +36
if (err.name === "EU Political Advertising Error") {
if (webhookId) {
err.message = err.message + ` (Webhook ID: ${webhookId})`
}
return
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To prevent potential runtime TypeErrors if err is null or undefined, use optional chaining (err?.name) to safely check the error name.

Suggested change
if (err.name === "EU Political Advertising Error") {
if (webhookId) {
err.message = err.message + ` (Webhook ID: ${webhookId})`
}
return
}
if (err?.name === "EU Political Advertising Error") {
if (webhookId) {
err.message = err.message + " (Webhook ID: " + webhookId + ")"
}
return
}

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant