Skip to content

Commit

Permalink
feature(raise-for-status) - handle too many requests
Browse files Browse the repository at this point in the history
  • Loading branch information
almogch committed Dec 17, 2024
1 parent 846ee41 commit 82469fa
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions intezer_sdk/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -27,49 +27,49 @@ 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


class IndexHasAlreadyBeenSentError(IntezerError):
def __init__(self):
super().__init__("Index already been sent")
super().__init__('Index already been sent')


IndexHasAlreadyBeenSent = IndexHasAlreadyBeenSentError


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


Expand All @@ -78,52 +78,52 @@ 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


class GlobalApiIsNotInitializedError(IntezerError):
def __init__(self):
super().__init__("Global API is not initialized")
super().__init__('Global API is not initialized')


GlobalApiIsNotInitialized = GlobalApiIsNotInitializedError


class AnalysisIsStillRunningError(IntezerError):
def __init__(self):
super().__init__("Analysis is still running")
super().__init__('Analysis is still running')


AnalysisIsStillRunning = AnalysisIsStillRunningError


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


class IndexFailedError(ServerError):
def __init__(self, response: requests.Response):
super().__init__("Index operation failed", response)
super().__init__('Index operation failed', response)


IndexFailed = IndexFailedError


class OperationStillRunningError(IntezerError):
def __init__(self, operation):
super().__init__(f"{operation} is still running")
super().__init__(f'{operation} is still running')


SubAnalysisOperationStillRunning = OperationStillRunningError
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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')

0 comments on commit 82469fa

Please sign in to comment.