From a724758caa0b0a9183ad472d19c3014cffe239b8 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 19 Sep 2022 20:04:52 -0400 Subject: [PATCH] Agent: Handle HTTPErrors in HTTPIslandAPIClient --- .../island_api_client/http_island_api_client.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/monkey/infection_monkey/island_api_client/http_island_api_client.py b/monkey/infection_monkey/island_api_client/http_island_api_client.py index 9d85447ea..15afd5e44 100644 --- a/monkey/infection_monkey/island_api_client/http_island_api_client.py +++ b/monkey/infection_monkey/island_api_client/http_island_api_client.py @@ -5,7 +5,14 @@ import requests from common.common_consts.timeouts import LONG_REQUEST_TIMEOUT, MEDIUM_REQUEST_TIMEOUT -from . import IIslandAPIClient, IslandAPIConnectionError, IslandAPIError, IslandAPITimeoutError +from . import ( + IIslandAPIClient, + IslandAPIConnectionError, + IslandAPIError, + IslandAPIRequestError, + IslandAPIRequestFailedError, + IslandAPITimeoutError, +) logger = logging.getLogger(__name__) @@ -17,6 +24,13 @@ def handle_island_errors(fn): return fn(*args, **kwargs) except requests.exceptions.ConnectionError as err: raise IslandAPIConnectionError(err) + except requests.exceptions.HTTPError as err: + if 400 <= err.response.status_code < 500: + raise IslandAPIRequestError(err) + elif 500 <= err.response.status_code < 600: + raise IslandAPIRequestFailedError(err) + else: + raise IslandAPIError(err) except TimeoutError as err: raise IslandAPITimeoutError(err) except Exception as err: