-
Notifications
You must be signed in to change notification settings - Fork 30
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-20359 Add custom exception handling. #48
base: TDL-20356-update-function-based-to-class-based
Are you sure you want to change the base?
TDL-20359 Add custom exception handling. #48
Conversation
# Verify that `time.sleep` was called for 'Retry-After' seconds from the header. | ||
mock_sleep.assert_any_call(int(retry_seconds)) | ||
|
||
def test_rate_limite_not_exceeded(self, mock_sleep, mock_request): |
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.
def test_rate_limite_not_exceeded(self, mock_sleep, mock_request): | |
def test_rate_limit_not_exceeded(self, mock_sleep, mock_request): |
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
tap_freshdesk/client.py
Outdated
@@ -7,7 +7,110 @@ | |||
|
|||
LOGGER = singer.get_logger() | |||
BASE_URL = "https://{}.freshdesk.com" | |||
DEFAULT_TIMEOUT = 300 |
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.
DEFAULT_TIMEOUT = 300 | |
REQUEST_TIMEOUT = 300 |
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
tap_freshdesk/client.py
Outdated
Set timeout value from config, if the value is passed. | ||
Else raise an exception. | ||
""" | ||
timeout = self.config.get("timeout", DEFAULT_TIMEOUT) |
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.
timeout = self.config.get("timeout", DEFAULT_TIMEOUT) | |
timeout = self.config.get("request_timeout", DEFAULT_TIMEOUT) |
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.
tap_freshdesk/client.py
Outdated
Set timeout value from config, if the value is passed. | ||
Else raise an exception. | ||
""" | ||
timeout = self.config.get("timeout", DEFAULT_TIMEOUT) |
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.
Add detail about request_timeout
in the README file.
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 detail about request_timeout
in the README file.
…L-20359-add-custom-exception-handling
tap_freshdesk/client.py
Outdated
}, | ||
403: { | ||
"raise_exception": FreshdeskAccessDeniedError, | ||
"message": "The agent whose credentials were used in making this request was not authorized to perform this API call." |
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 agent whose credentials were used in making this request was not authorized to perform this API call." | |
"message": "The agent whose credentials were used to make this request was not authorized to perform this API call." |
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
tap_freshdesk/streams.py
Outdated
# Skipping 404 error as it is returned for deleted tickets and spam | ||
LOGGER.warning("Could not retrieve time entries for ticket id {}. This may be caused by tickets " | ||
"marked as spam or deleted.".format(self.parent_id)) | ||
pass |
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.
No meaning of this line
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.
Removed pass
statement.
(409, "AInconsistent/Conflicting State", client.FreshdeskConflictingStateError), | ||
(415, "Unsupported Content-type", client.FreshdeskUnsupportedContentError), | ||
(429, "Rate Limit Exceeded", client.FreshdeskRateLimitError), | ||
(500, "Unexpected Server Error", client.FreshdeskServerError), |
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.
Take one unexpected error as well like 503 or 505
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 test case to verify 503
status code.
…L-20359-add-custom-exception-handling
tap_freshdesk/client.py
Outdated
500: { | ||
"raise_exception": FreshdeskServerError, | ||
"message": "Unexpected Server Error." | ||
}, |
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.
}, | |
} |
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
""" | ||
Retrieve the error code and the error message from the response and return custom exceptions accordingly. | ||
""" | ||
try: |
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.
Why do we need this? We can call this function if status_code is not equal to 200
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.
Agree @dbshah1212. Removed try-except
and raising error directly if status_code
is not equal to 200.
…L-20359-add-custom-exception-handling
Description of change
5xx errors
,TimeoutError
andConnnectionError
.time_entries
stream.Manual QA steps
Risks
Rollback steps