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

TDL-17516: Add custom exception handling #8

Merged
merged 9 commits into from
Feb 24, 2022

Conversation

hpatel41
Copy link
Contributor

@hpatel41 hpatel41 commented Feb 2, 2022

Description of change

TDL-17516: Add custom exception handling

  • Added error handling based on the document

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

  • revert this branch

@savan-chovatiya savan-chovatiya marked this pull request as ready for review February 2, 2022 07:00
},
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."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated error message.

Comment on lines +117 to +119
if status_code == 403 and error_code == 99:
LOGGER.warning("{}".format(json_response))

Copy link
Contributor

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.

if response.status_code == 403 and response.json().get("error") == 99:
# pylint: disable=logging-fstring-interpolation
LOGGER.warning(f"{response.json()}")
return response.json()

Copy link
Contributor Author

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.

"message": "API rate limit exceeded, please retry after some time."
},
500: {
"raise_exception": SailthruServer5xxError,

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.

Copy link
Contributor Author

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:

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.

Copy link
Contributor Author

@hpatel41 hpatel41 Feb 2, 2022

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.

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.

Copy link
Contributor Author

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):

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.

Copy link
Contributor Author

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

@hpatel41 hpatel41 requested a review from dbshah1212 February 2, 2022 11:51
@hpatel41 hpatel41 merged commit 9a46e85 into crest-work Feb 24, 2022
@hpatel41 hpatel41 mentioned this pull request Feb 24, 2022
KrisPersonal pushed a commit that referenced this pull request Mar 2, 2022
* 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]>
@KrisPersonal KrisPersonal mentioned this pull request Mar 2, 2022
@somethingmorerelevant somethingmorerelevant deleted the TDL-17516-add-exception-handling branch February 15, 2023 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants