-
Notifications
You must be signed in to change notification settings - Fork 6
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
TDL-17516: Add custom exception handling #8
Conversation
tap_sailthru/client.py
Outdated
}, | ||
404: { | ||
"raise_exception": SailthruNotFoundError, | ||
"message": "The resource you have specified cannot be found. Either the accounts provided are invalid or you do not have access to the Ad Account." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"message": "The resource you have specified cannot be found. Either the accounts provided are invalid or you do not have access to the Ad Account." | |
"message": "The resource you have specified cannot be found." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated error message.
if status_code == 403 and error_code == 99: | ||
LOGGER.warning("{}".format(json_response)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tap was not raising exceptions for the above specific condition earlier so update this to not raise expectation for this particular scenario.
tap-sailthru/tap_sailthru/client.py
Lines 237 to 240 in 249d3ae
if response.status_code == 403 and response.json().get("error") == 99: | |
# pylint: disable=logging-fstring-interpolation | |
LOGGER.warning(f"{response.json()}") | |
return response.json() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is an error, we should raise it instead of returning the response. As the Tap is expecting data from the response, it may break at another location.
tap_sailthru/client.py
Outdated
"message": "API rate limit exceeded, please retry after some time." | ||
}, | ||
500: { | ||
"raise_exception": SailthruServer5xxError, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do define 5xx and 500 differently. Make 500 a sub-class of 5xx because it is an internal server error specifically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
def get_exception_for_status_code(status_code, error_code): | ||
if status_code >= 500: | ||
return SailthruServer5xxError | ||
if status_code == 400 and error_code == 99: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add comments for this specific scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition was already present, we have just changed the location.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still better to add the comment for future developers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We did not find any doc regarding this, not sure why it was implemented before.
|
||
return ERROR_CODE_EXCEPTION_MAPPING.get(status_code, {}).get("raise_exception", SailthruClientError) | ||
|
||
def raise_for_error(response): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provide function comments for all functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
@@ -0,0 +1,253 @@ | |||
from unittest import mock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do provide test function comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
* TDL-17511-Add missing test case, TDL-17522-Fix typos in the fields (#5) * Added all the integration test cases * Added one assertion in discovery test * used pytest with coverage * removed un-used line from config.yml file * reverted the change * updated config.yml file for unittest coverage * removed user_agent from base test file * skip blast_query from start date and bookmark tests * removed unsed imports and updated state bookmark in bookmark test * removed setuptools * resolved bookmark test failure * resolved bookmark test failure * include blast_query stream in test cases Co-authored-by: harshpatel4_crest <[email protected]> * TDL-17521: Fix date_windowing for the purchase_log stream (#9) * Added all the integration test cases * updated date window for purchase log stream * run purchase log stream in start date test * Added one assertion in discovery test * used pytest with coverage * removed un-used line from config.yml file * reverted the change * updated config.yml file for unittest coverage * removed user_agent from base test file * skip blast_query from start date and bookmark tests Co-authored-by: Umang Agrawal <[email protected]> * TDL-17514: Implement request timeout (#6) * Added request timeout * Resolved review comments * run CCi build * updated config,yml file for unittest reports * removed user_agent and imported tap tester libs in base test file Co-authored-by: harshpatel4_crest <[email protected]> * TDL-17515: Verify credentials in discover mode (#7) * Added credentials check in discover mode * updated unittest and run CCi * removed user_agent from base file test * imported runner in base test file * imported menagerie in base test file Co-authored-by: harshpatel4_crest <[email protected]> * TDL-17516: Add custom exception handling (#8) * added exception handling * updated 404 error message * added 500 error class and comments * run CCi build and updated unittest assertion * updated config.yml file * updated config.yml file * removed user_agent from base test file * imported tap tester libs in base * TDL-17520: Primary Key is not unique for the purchase_log stream (#10) * updated primary key for purchase_log stream * removed user_agent from base test file * imported tap_tester in base test file * added channel in the primary key for purchase log * resolve pylint error * resolve unittest failure * skip 403 and 99 error, updated automatic test case for purchase_log stream Co-authored-by: Umang Agrawal <[email protected]> Co-authored-by: Umang Agrawal <[email protected]> Co-authored-by: savan-chovatiya <[email protected]>
Description of change
TDL-17516: Add custom exception handling
NOTE: the build is failing due to integration tests failure but that is fixed and all tests are written as part of #5
Manual QA steps
Risks
Rollback steps