From b8845d809ac865a89427b981d19e25c7c1f02b1c Mon Sep 17 00:00:00 2001 From: a-rampalli Date: Tue, 26 Dec 2023 13:22:11 +0530 Subject: [PATCH] chore: handles non number rate_limit_reset header --- .../source-sendgrid/source_sendgrid/streams.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/airbyte-integrations/connectors/source-sendgrid/source_sendgrid/streams.py b/airbyte-integrations/connectors/source-sendgrid/source_sendgrid/streams.py index 867c2219d96c..0ce4856e65e4 100644 --- a/airbyte-integrations/connectors/source-sendgrid/source_sendgrid/streams.py +++ b/airbyte-integrations/connectors/source-sendgrid/source_sendgrid/streams.py @@ -81,10 +81,13 @@ def backoff_time(self, response: requests.Response) -> float: response_headers = response.headers RATE_LIMIT_RESET_HEADER = "x-ratelimit-reset" if RATE_LIMIT_RESET_HEADER in response_headers: - # Assumes it is a number - sleep_time = int(response_headers.get(RATE_LIMIT_RESET_HEADER)) + 1 - self.logger.info(f"Rate limit exceeded. Sleeping for {sleep_time} seconds") - return sleep_time + try: + sleep_time = int(response_headers.get(RATE_LIMIT_RESET_HEADER)) + 1 + self.logger.info(f"Rate limit exceeded. Sleeping for {sleep_time} seconds") + return sleep_time + except ValueError: + # Log error and use default exponential backoff + self.logger.error(f"Rate limit reset header value is not a number. Value: {response_headers.get(RATE_LIMIT_RESET_HEADER)}") # Use default exponential backoff if rate limit headers are not present return super().backoff_time(response)