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..00d83ac 100644 --- a/intezer_sdk/errors.py +++ b/intezer_sdk/errors.py @@ -177,3 +177,11 @@ 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) + 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')