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-20359 Add custom exception handling. #48

Open
wants to merge 13 commits into
base: TDL-20356-update-function-based-to-class-based
Choose a base branch
from

Conversation

prijendev
Copy link

@prijendev prijendev commented Aug 23, 2022

Description of change

  • Added custom exception class for each error code.
  • Added backoff logic to retry all 5xx errors, TimeoutError and ConnnectionError.
  • Set default timeout of 6 seconds as per documentation.
  • Added request timeout.
  • Skip 404 error for time_entries stream.
  • Added unit tests to verify error messages and retry counts.

Manual QA steps

Risks

Rollback steps

  • revert this branch

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

Choose a reason for hiding this comment

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

Suggested change
def test_rate_limite_not_exceeded(self, mock_sleep, mock_request):
def test_rate_limit_not_exceeded(self, mock_sleep, mock_request):

Copy link
Author

Choose a reason for hiding this comment

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

Updated

@@ -7,7 +7,110 @@

LOGGER = singer.get_logger()
BASE_URL = "https://{}.freshdesk.com"
DEFAULT_TIMEOUT = 300

Choose a reason for hiding this comment

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

Suggested change
DEFAULT_TIMEOUT = 300
REQUEST_TIMEOUT = 300

Copy link
Author

Choose a reason for hiding this comment

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

Updated

Set timeout value from config, if the value is passed.
Else raise an exception.
"""
timeout = self.config.get("timeout", DEFAULT_TIMEOUT)

Choose a reason for hiding this comment

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

Suggested change
timeout = self.config.get("timeout", DEFAULT_TIMEOUT)
timeout = self.config.get("request_timeout", DEFAULT_TIMEOUT)

Copy link
Author

Choose a reason for hiding this comment

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

Updated.

Set timeout value from config, if the value is passed.
Else raise an exception.
"""
timeout = self.config.get("timeout", DEFAULT_TIMEOUT)

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.

Copy link
Author

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.

},
403: {
"raise_exception": FreshdeskAccessDeniedError,
"message": "The agent whose credentials were used in making this request was not authorized to perform this API call."

Choose a reason for hiding this comment

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

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

Copy link
Author

Choose a reason for hiding this comment

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

Updated

# 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

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

Copy link
Author

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),
Copy link

@dbshah1212 dbshah1212 Aug 25, 2022

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

Copy link
Author

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.

500: {
"raise_exception": FreshdeskServerError,
"message": "Unexpected Server Error."
},

Choose a reason for hiding this comment

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

Suggested change
},
}

Copy link
Author

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:

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

Copy link
Author

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.

@dbshah1212 dbshah1212 self-requested a review September 8, 2022 05:05
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.

4 participants