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

🐛 Source Paypal Transaction: report full error message details, updated check method #8580

Merged
Merged
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ Customize `acceptance-test-config.yml` file to configure tests. See [Source Acce
If your connector requires to create or destroy resources for use during acceptance tests create fixtures for it and place them inside integration_tests/acceptance.py.
To run your integration tests with acceptance tests, from the connector root, run
```
python -m pytest integration_tests -p integration_tests.acceptance
docker build . --no-cache -t airbyte/source-paypal-transaction:dev \
&& python -m pytest -p source_acceptance_test.plugin
```
To run your integration tests with docker

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#

import json
import logging
import time
from abc import ABC
Expand All @@ -16,6 +17,30 @@
from dateutil.parser import isoparse


class PaypalHttpException(Exception):
"""HTTPError Exception with detailed info"""

def __init__(self, error: requests.exceptions.HTTPError):
self.error = error

def __str__(self):
message = repr(self.error)

if self.error.response.content:
content = self.error.response.content.decode()
try:
details = json.loads(content)
except json.decoder.JSONDecodeError:
details = content

message = f"{message} Details: {details}"

return message

def __repr__(self):
return self.__str__()


def get_endpoint(is_sandbox: bool = False) -> str:
if is_sandbox:
endpoint = "https://api-m.sandbox.paypal.com"
Expand Down Expand Up @@ -227,6 +252,12 @@ def stream_slices(

return slices

def _send_request(self, request: requests.PreparedRequest, request_kwargs: Mapping[str, Any]) -> requests.Response:
try:
return super()._send_request(request, request_kwargs)
except requests.exceptions.HTTPError as http_error:
raise PaypalHttpException(http_error)


class Transactions(PaypalTransactionStream):
"""List Paypal Transactions on a specific date range
Expand Down Expand Up @@ -351,11 +382,28 @@ def check_connection(self, logger, config) -> Tuple[bool, any]:

# Try to initiate a stream and validate input date params
try:
# validate input date ranges
Transactions(authenticator=authenticator, **config).validate_input_dates()
except Exception as e:
return False, e

return True, None
# validate if Paypal API is able to extract data for given start_data
start_date = isoparse(config["start_date"])
end_date = start_date + timedelta(days=1)
stream_slice = {
"start_date": start_date.isoformat(),
"end_date": end_date.isoformat(),
}
records = Transactions(authenticator=authenticator, **config).read_records(
sync_mode=None,
stream_slice=stream_slice
)
# Try to read one value from records iterator
next(records, None)
return True, None
except Exception as e:
if "Data for the given start date is not available" in repr(e):
midavadim marked this conversation as resolved.
Show resolved Hide resolved
return False, f"Data for the given start date ({config['start_date']}) is not available, please use more recent start date"
else:
return False, e

def streams(self, config: Mapping[str, Any]) -> List[Stream]:
"""
Expand Down