Agent: Handle HTTPErrors in HTTPIslandAPIClient

This commit is contained in:
Mike Salvatore 2022-09-19 20:04:52 -04:00
parent cb8fda0bec
commit a724758caa
1 changed files with 15 additions and 1 deletions

View File

@ -5,7 +5,14 @@ import requests
from common.common_consts.timeouts import LONG_REQUEST_TIMEOUT, MEDIUM_REQUEST_TIMEOUT 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__) logger = logging.getLogger(__name__)
@ -17,6 +24,13 @@ def handle_island_errors(fn):
return fn(*args, **kwargs) return fn(*args, **kwargs)
except requests.exceptions.ConnectionError as err: except requests.exceptions.ConnectionError as err:
raise IslandAPIConnectionError(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: except TimeoutError as err:
raise IslandAPITimeoutError(err) raise IslandAPITimeoutError(err)
except Exception as err: except Exception as err: