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

Enhance error handling in sync_stream function #124

Open
wants to merge 1 commit into
base: master
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
21 changes: 21 additions & 0 deletions tap_quickbooks/quickbooks/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
# pylint: disable=super-init-not-called
import requests

def raise_for_invalid_credentials(resp):
def message_to_dict(input_string):
# Split the string by commas to separate each key-value pair
pairs = input_string.split("; ")

# Create a dictionary by splitting each pair by '=' and using them as key-value
result_dict = {key: value for key, value in (pair.split("=") for pair in pairs)}

return result_dict

try:
response_dict_message = resp.json()["fault"]["error"][0]["message"]
response_dict = message_to_dict(response_dict_message)
if response_dict["statusCode"] == "403":
raise requests.HTTPError(f"[{response_dict['statusCode']}] Your credentials are invalid. Please check if you are using sandbox credentials to access production data and try again.",request=resp.request,response=resp)
except requests.exceptions.HTTPError as ex:
raise ex
except Exception:
pass

class TapQuickbooksException(Exception):
pass
Expand Down
9 changes: 7 additions & 2 deletions tap_quickbooks/quickbooks/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import singer.utils as singer_utils

from requests.exceptions import HTTPError
from tap_quickbooks.quickbooks.exceptions import TapQuickbooksException
from tap_quickbooks.quickbooks.exceptions import TapQuickbooksException, raise_for_invalid_credentials
from requests.models import Response

LOGGER = singer.get_logger()

Expand Down Expand Up @@ -73,7 +74,11 @@ def _query_recur(
day_range,
catalog_entry['stream'])
retryable = True
except:
else:
raise_for_invalid_credentials(ex.response)
except HTTPError as http_ex:
raise http_ex
except Exception:
raise ex

if retryable:
Expand Down