Skip to content

Commit

Permalink
hack the right status code
Browse files Browse the repository at this point in the history
  • Loading branch information
epwalsh committed Jul 8, 2024
1 parent 8bd8596 commit b64ee4e
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions beaker/services/service_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ def make_request(session: requests.Session) -> requests.Response:
else:
self.logger.debug("RECV %s %s %s", method, url, response)

if exceptions_for_status is not None and response.status_code in exceptions_for_status:
raise exceptions_for_status[response.status_code]
status_code = response.status_code

try:
response.raise_for_status()
Expand All @@ -119,16 +118,20 @@ def make_request(session: requests.Session) -> requests.Response:
except (TypeError, KeyError, json.JSONDecodeError):
pass

if (
msg is not None
and response.status_code is not None
and 400 <= response.status_code < 500
):
# HACK: sometimes Beaker doesn't use the right error code, so we try to guess based
# on the message.
if status_code == 400 and msg is not None and "already in use" in msg:
status_code = 409

if exceptions_for_status is not None and status_code in exceptions_for_status:
raise exceptions_for_status[status_code]

if msg is not None and status_code is not None and 400 <= status_code < 500:
# Raise a BeakerError if we're misusing the API (4xx error code).
if response.status_code == 403:
if status_code == 403:
raise BeakerPermissionsError(msg)
else:
raise BeakerError(msg)
raise BeakerError(f"[code={status_code}] {msg}")
elif msg is not None:
raise HTTPError(msg, response=response) # type: ignore
else:
Expand Down

0 comments on commit b64ee4e

Please sign in to comment.