Skip to content

Commit

Permalink
Align response format
Browse files Browse the repository at this point in the history
  • Loading branch information
TShapinsky committed Dec 15, 2023
1 parent d21c09c commit 8a86503
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions alfalfa_client/alfalfa_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,13 @@ def _request(self, endpoint: str, method="POST", parameters=None) -> requests.Re
else:
response = requests.request(method=method, url=self.url + endpoint)

if response.status_code == 400 or response.status_code == 500:
if response.status_code >= 400:
try:
body = response.json()
raise AlfalfaAPIException(body["error"])
exception = AlfalfaAPIException(body["message"])
if "payload" in body:
exception.add_note(json.dumps(body["payload"]))
raise exception
except json.JSONDecodeError:
pass
response.raise_for_status()
Expand Down

0 comments on commit 8a86503

Please sign in to comment.