Skip to content

Commit

Permalink
feature(api) - update raise from status to support too many request e…
Browse files Browse the repository at this point in the history
…rror
  • Loading branch information
almogch committed Dec 17, 2024
1 parent 710defa commit 6ebd5bc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion intezer_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.21.6'
__version__ = '1.21.7'
3 changes: 2 additions & 1 deletion intezer_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Expand Down
4 changes: 4 additions & 0 deletions intezer_sdk/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 6ebd5bc

Please sign in to comment.