From 82469fa17bca6ccbddffeb2c09ad2e72f817d3f6 Mon Sep 17 00:00:00 2001 From: almogch Date: Tue, 17 Dec 2024 22:32:55 +0200 Subject: [PATCH] feature(raise-for-status) - handle too many requests --- intezer_sdk/errors.py | 60 +++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/intezer_sdk/errors.py b/intezer_sdk/errors.py index ab016e5..2daec82 100644 --- a/intezer_sdk/errors.py +++ b/intezer_sdk/errors.py @@ -6,9 +6,9 @@ def _parse_erroneous_response(response: requests.Response): try: data = response.json() - return data.get("error", "") + return data.get('error', '') except ValueError: - return "" + return '' class IntezerError(Exception): @@ -27,13 +27,13 @@ def __init__(self, message: str, response: requests.Response): self.response = response detailed_error = _parse_erroneous_response(response) if detailed_error: - message = f"{message}. Error:{detailed_error}" + message = f'{message}. Error:{detailed_error}' super().__init__(message) class AnalysisHasAlreadyBeenSentError(IntezerError): def __init__(self): - super().__init__("Analysis already been sent") + super().__init__('Analysis already been sent') AnalysisHasAlreadyBeenSent = AnalysisHasAlreadyBeenSentError @@ -41,7 +41,7 @@ def __init__(self): class IndexHasAlreadyBeenSentError(IntezerError): def __init__(self): - super().__init__("Index already been sent") + super().__init__('Index already been sent') IndexHasAlreadyBeenSent = IndexHasAlreadyBeenSentError @@ -49,27 +49,27 @@ def __init__(self): class FamilyNotFoundError(IntezerError): def __init__(self, family_id: str): - super().__init__(f"Family not found: {family_id}") + super().__init__(f'Family not found: {family_id}') class HashDoesNotExistError(ServerError): def __init__(self, response: requests.Response): - super().__init__("Hash was not found", response) + super().__init__('Hash was not found', response) class FileTooLargeError(ServerError): def __init__(self, response: requests.Response): - super().__init__("File is too large", response) + super().__init__('File is too large', response) class ReportDoesNotExistError(IntezerError): def __init__(self): - super().__init__("Report was not found") + super().__init__('Report was not found') class AnalysisIsAlreadyRunningError(ServerError): def __init__(self, response: requests.Response, running_analysis_id: Optional[str]): - super().__init__("Analysis already running", response) + super().__init__('Analysis already running', response) self.analysis_id = running_analysis_id @@ -78,7 +78,7 @@ def __init__(self, response: requests.Response, running_analysis_id: Optional[st class InsufficientQuotaError(ServerError): def __init__(self, response: requests.Response): - super().__init__("Insufficient quota", response) + super().__init__('Insufficient quota', response) InsufficientQuota = InsufficientQuotaError @@ -86,7 +86,7 @@ def __init__(self, response: requests.Response): class GlobalApiIsNotInitializedError(IntezerError): def __init__(self): - super().__init__("Global API is not initialized") + super().__init__('Global API is not initialized') GlobalApiIsNotInitialized = GlobalApiIsNotInitializedError @@ -94,7 +94,7 @@ def __init__(self): class AnalysisIsStillRunningError(IntezerError): def __init__(self): - super().__init__("Analysis is still running") + super().__init__('Analysis is still running') AnalysisIsStillRunning = AnalysisIsStillRunningError @@ -102,12 +102,12 @@ def __init__(self): class AnalysisFailedError(IntezerError): def __init__(self): - super().__init__("Analysis failed") + super().__init__('Analysis failed') class InvalidApiKeyError(ServerError): def __init__(self, response: requests.Response): - super().__init__("Invalid api key", response) + super().__init__('Invalid api key', response) InvalidApiKey = InvalidApiKeyError @@ -115,7 +115,7 @@ def __init__(self, response: requests.Response): class IndexFailedError(ServerError): def __init__(self, response: requests.Response): - super().__init__("Index operation failed", response) + super().__init__('Index operation failed', response) IndexFailed = IndexFailedError @@ -123,7 +123,7 @@ def __init__(self, response: requests.Response): class OperationStillRunningError(IntezerError): def __init__(self, operation): - super().__init__(f"{operation} is still running") + super().__init__(f'{operation} is still running') SubAnalysisOperationStillRunning = OperationStillRunningError @@ -132,12 +132,12 @@ def __init__(self, operation): class SubAnalysisNotFoundError(IntezerError): def __init__(self, analysis_id: str): - super().__init__(f"analysis {analysis_id} is not found") + super().__init__(f'analysis {analysis_id} is not found') class InsufficientPermissionsError(ServerError): def __init__(self, response: requests.Response): - super().__init__("Account does not have permission to this route", response) + super().__init__('Account does not have permission to this route', response) class AlertError(IntezerError): @@ -146,19 +146,19 @@ class AlertError(IntezerError): class InvalidAlertMappingError(AlertError): def __init__(self, response: requests.Response): - super().__init__("Bad request - the mapping is probably malformed", response) + super().__init__('Bad request - the mapping is probably malformed', response) class AlertInProgressError(AlertError): def __init__(self, alert_id: str): super().__init__( - f"The alert {alert_id} is being processed at the moment, please try again later" + f'The alert {alert_id} is being processed at the moment, please try again later' ) class AlertNotFoundError(AlertError): def __init__(self, alert_id: str): - super().__init__(f"The given alert does not exist - {alert_id}") + super().__init__(f'The given alert does not exist - {alert_id}') class InvalidAlertArgumentError(AlertError): @@ -168,23 +168,23 @@ def __init__(self, message: str): class UrlOfflineError(ServerError): def __init__(self, response: requests.Response): - super().__init__("Url is offline", response) + super().__init__('Url is offline', response) class InvalidUrlError(ServerError): def __init__(self, response: requests.Response): - super().__init__("Invalid url", response) + super().__init__('Invalid url', response) class AnalysisSkippedByRuleError(ServerError): def __init__(self, response: requests.Response): - super().__init__("Analysis skipped by rule", 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") + 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')