From bc0d2e9e1e5ffb48050457679989558d2154598f Mon Sep 17 00:00:00 2001 From: Jonathan Abrahamy Date: Mon, 23 Oct 2023 09:40:52 +0200 Subject: [PATCH] feat(url analysis): Add invalid url error TKT-1270 --- CHANGES | 5 +++++ intezer_sdk/__init__.py | 2 +- intezer_sdk/_api.py | 6 +++++- intezer_sdk/errors.py | 9 +++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 78a1c48..28fb539 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +1.19.6 +------ +- Add InvalidUrlError +- Add details to analysis server error + 1.19.5 ------ - Latest URL analysis fallback. diff --git a/intezer_sdk/__init__.py b/intezer_sdk/__init__.py index 7816d82..7a1a040 100644 --- a/intezer_sdk/__init__.py +++ b/intezer_sdk/__init__.py @@ -1 +1 @@ -__version__ = '1.19.5' +__version__ = '1.19.6' diff --git a/intezer_sdk/_api.py b/intezer_sdk/_api.py index 31e3fe3..6831e71 100644 --- a/intezer_sdk/_api.py +++ b/intezer_sdk/_api.py @@ -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) diff --git a/intezer_sdk/errors.py b/intezer_sdk/errors.py index 2d5d612..d66ec71 100644 --- a/intezer_sdk/errors.py +++ b/intezer_sdk/errors.py @@ -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') @@ -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)