From 6ebd5bcd4d80b1464b5ac4aa44477e075231e4c4 Mon Sep 17 00:00:00 2001 From: almogch Date: Tue, 17 Dec 2024 12:56:13 +0200 Subject: [PATCH 1/2] feature(api) - update raise from status to support too many request error --- CHANGES | 4 ++++ intezer_sdk/__init__.py | 2 +- intezer_sdk/api.py | 3 ++- intezer_sdk/errors.py | 4 ++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 595df02..3862bea 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +1.21.7 +_______ +- Raise AnalysisRateLimitError when analysis rejected due to rate limit exceeded error returning from server + 1.21.6 _______ - Fix sending data in the body of the request diff --git a/intezer_sdk/__init__.py b/intezer_sdk/__init__.py index b93f5dc..3bdbfad 100644 --- a/intezer_sdk/__init__.py +++ b/intezer_sdk/__init__.py @@ -1 +1 @@ -__version__ = '1.21.6' +__version__ = '1.21.7' diff --git a/intezer_sdk/api.py b/intezer_sdk/api.py index af769a8..2170381 100644 --- a/intezer_sdk/api.py +++ b/intezer_sdk/api.py @@ -51,13 +51,14 @@ def raise_for_status(response: requests.Response, elif response.status_code == HTTPStatus.CONFLICT: if response_json.get('result', {}).get('is_skipped_by_rule'): raise errors.AnalysisSkippedByRuleError(response) + elif response.status_code == HTTPStatus.TOO_MANY_REQUESTS: + raise errors.AnalysisRateLimitError(response) elif response.status_code == HTTPStatus.FORBIDDEN: if response_json.get('error') == 'Insufficient Permissions': raise errors.InsufficientPermissionsError(response) elif response.status_code == HTTPStatus.BAD_REQUEST: http_error_msg = '\n'.join([f'{key}:{value}.' for key, value in response_json.get('message', {}).items()]) - if should_raise: if not http_error_msg: http_error_msg = f'{response.status_code} Client Error: {reason} for url: {response.url}' diff --git a/intezer_sdk/errors.py b/intezer_sdk/errors.py index 8680048..60bf582 100644 --- a/intezer_sdk/errors.py +++ b/intezer_sdk/errors.py @@ -177,3 +177,7 @@ def __init__(self, response: requests.Response): class AnalysisSkippedByRuleError(ServerError): def __init__(self, response: requests.Response): super().__init__('Analysis skipped by rule', response) + +class AnalysisRateLimitError(ServerError): + def __init__(self, response: requests.Response): + super().__init__('Analysis rate limit reached', response) From 99f7f2ec78345e76c73744e053bc8b2d69951de9 Mon Sep 17 00:00:00 2001 From: almogch Date: Tue, 17 Dec 2024 13:06:57 +0200 Subject: [PATCH 2/2] feature(api) - update raise from status to support too many request error --- intezer_sdk/errors.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/intezer_sdk/errors.py b/intezer_sdk/errors.py index 60bf582..00d83ac 100644 --- a/intezer_sdk/errors.py +++ b/intezer_sdk/errors.py @@ -181,3 +181,7 @@ def __init__(self, response: requests.Response): class AnalysisRateLimitError(ServerError): def __init__(self, response: requests.Response): super().__init__('Analysis rate limit reached', response) + self.limit = response.headers.get('X-RateLimit-Limit') + self.remaining = response.headers.get('X-RateLimit-Remaining') + self.reset_time_in_sec = response.headers.get('X-RateLimit-Reset') + self.retry_after = response.headers.get('Retry-After')