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

fix: Resume on all 403 Forbidden responses #83

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tap_googleads/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
21 changes: 1 addition & 20 deletions tap_googleads/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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."""
Expand Down