Skip to content

Commit

Permalink
404s shouldn't be caught cause that breaks other logic
Browse files Browse the repository at this point in the history
  • Loading branch information
TShapinsky committed Dec 15, 2023
1 parent 8a86503 commit 1cfc6e1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions alfalfa_client/alfalfa_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ 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:
if response.status_code == 400 or response.status_code == 500:
try:
body = response.json()
exception = AlfalfaAPIException(body["message"])
if "payload" in body:
exception.add_note(json.dumps(body["payload"]))
exception.add_payload(json.dumps(body["payload"]))
raise exception
except json.JSONDecodeError:
pass
Expand Down
9 changes: 9 additions & 0 deletions alfalfa_client/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from os import PathLike, path
from pathlib import Path
from typing import List
import json


def parallelize(func):
Expand Down Expand Up @@ -119,6 +120,14 @@ class AlfalfaWorkerException(AlfalfaException):

class AlfalfaAPIException(AlfalfaException):
"""Wrapper for API errors"""
def add_payload(self, payload):
self.payload = payload

def __str__(self) -> str:
if self.payload:
return super().__str__() + '\nAPI Payload: \n' + json.dumps(self.payload)
return super().__str__()



class AlfalfaClientException(AlfalfaException):
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/test_single_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ def test_alias(client: AlfalfaClient, internal_clock_run_id: str):
client.set_alias("test", internal_clock_run_id)
assert client.get_alias("test") == internal_clock_run_id

sim_time = client.get_sim_time(internal_clock_run_id)
alias_sim_time = client.get_sim_time("test")
assert sim_time == alias_sim_time

client.advance("test")
sim_time = client.get_sim_time(internal_clock_run_id)
alias_sim_time = client.get_sim_time("test")
assert sim_time == alias_sim_time

# @pytest.mark.integration
# def test_error_handling(client: AlfalfaClient, run_id: str):
Expand Down

0 comments on commit 1cfc6e1

Please sign in to comment.