Skip to content

Commit

Permalink
Merge pull request #120 from intezer/feature/add-invalid-url-error
Browse files Browse the repository at this point in the history
feat(url analysis): Add invalid url error TKT-1270
  • Loading branch information
yoniabrahamy authored Oct 23, 2023
2 parents 9fef251 + bc0d2e9 commit 6796395
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.19.6
------
- Add InvalidUrlError
- Add details to analysis server error

1.19.5
------
- Latest URL analysis fallback.
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.19.5'
__version__ = '1.19.6'
6 changes: 5 additions & 1 deletion intezer_sdk/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,11 +741,15 @@ def _assert_analysis_response_status_code(response: Response):
elif response.status_code == HTTPStatus.BAD_REQUEST:
data = response.json()
error = data.get('error', '')
details = data.get('details', '')
result = data.get('result', {})
if result.get('is_url_offline'):
raise errors.UrlOfflineError(response)

raise errors.ServerError(f'Server returned bad request error: {error}', response)
if error == 'Invalid url':
raise errors.InvalidUrlError(response)

raise errors.ServerError(f'Server returned bad request error: {error}, details: {details}', response)
elif response.status_code != HTTPStatus.CREATED:
raise errors.ServerError(f'Error in response status code:{response.status_code}', response)

Expand Down
9 changes: 9 additions & 0 deletions intezer_sdk/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ class HashDoesNotExistError(ServerError):
def __init__(self, response: requests.Response):
super().__init__('Hash was not found', response)


class FileTooLargeError(ServerError):
def __init__(self, response: requests.Response):
super().__init__('File is too large', response)


class ReportDoesNotExistError(IntezerError):
def __init__(self):
super().__init__('Report was not found')
Expand Down Expand Up @@ -156,10 +158,17 @@ class AlertNotFoundError(AlertError):
def __init__(self, alert_id: str):
super().__init__(f'The given alert does not exist - {alert_id}')


class InvalidAlertArgumentError(AlertError):
def __init__(self, message: str):
super().__init__(message)


class UrlOfflineError(ServerError):
def __init__(self, response: requests.Response):
super().__init__('Url is offline', response)


class InvalidUrlError(ServerError):
def __init__(self, response: requests.Response):
super().__init__('Invalid url', response)

0 comments on commit 6796395

Please sign in to comment.