diff --git a/tap_googleads/client.py b/tap_googleads/client.py index fb51ab1..cb30f46 100644 --- a/tap_googleads/client.py +++ b/tap_googleads/client.py @@ -2,6 +2,7 @@ from datetime import datetime from functools import cached_property +from http import HTTPStatus from typing import Any, Dict, Optional import requests @@ -57,6 +58,13 @@ def response_error_message(self, response: requests.Response) -> str: except Exception: return base_msg + def validate_response(self, response): + if response.status_code == HTTPStatus.FORBIDDEN: + msg = self.response_error_message(response) + raise ResumableAPIError(msg, response) + + super().validate_response(response) + @cached_property def authenticator(self) -> OAuthAuthenticator: """Return a new authenticator object.""" diff --git a/tap_googleads/streams.py b/tap_googleads/streams.py index 85025de..5676de3 100644 --- a/tap_googleads/streams.py +++ b/tap_googleads/streams.py @@ -3,13 +3,12 @@ from __future__ import annotations import datetime -from http import HTTPStatus from pathlib import Path from typing import TYPE_CHECKING, Any, Dict, Iterable from singer_sdk import typing as th # JSON Schema typing helpers -from tap_googleads.client import GoogleAdsStream, ResumableAPIError +from tap_googleads.client import GoogleAdsStream if TYPE_CHECKING: from singer_sdk.helpers.types import Context, Record @@ -101,13 +100,6 @@ def gaql(self): seen_customer_ids = set() - def validate_response(self, response): - if response.status_code == HTTPStatus.FORBIDDEN: - msg = self.response_error_message(response) - raise ResumableAPIError(msg, response) - - super().validate_response(response) - def generate_child_contexts(self, record, context): customer_ids = self.customer_ids @@ -260,17 +252,6 @@ def request_records(self, context): yield from records - def validate_response(self, response): - if response.status_code == HTTPStatus.FORBIDDEN: - error = response.json()["error"]["details"][0]["errors"][0] - msg = ( - "Click view report not accessible to customer " - f"'{self.context['customer_id']}': {error['message']}" - ) - raise ResumableAPIError(msg, response) - - super().validate_response(response) - class CampaignsStream(ReportsStream): """Define custom stream."""