Skip to content

Commit

Permalink
Changed handling of state; Improved error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
prouast committed Jan 4, 2025
1 parent b57d098 commit 334b192
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions tests/test_vitallens.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def create_mock_api_response(
"ppg_waveform": {"data": np.random.rand(video.shape[0]).tolist(), "unit": "unitless", "confidence": np.ones(video.shape[0]).tolist(), "note": "Note"},
"respiratory_waveform": {"data": np.random.rand(video.shape[0]).tolist(), "unit": "unitless", "confidence": np.ones(video.shape[0]).tolist(), "note": "Note"}},
"face": {"confidence": np.random.rand(video.shape[0]).tolist(), "note": "Note"},
"state": {"data": np.zeros((2, 128), dtype=np.float32).tolist(), "note": "Note"},
"state": {"data": np.zeros((256,), dtype=np.float32).tolist(), "note": "Note"},
"message": "Message"})

@pytest.mark.parametrize("file", [True, False])
Expand Down Expand Up @@ -167,7 +167,7 @@ def test_VitalLens_API_valid_response(request, process_signals, n_frames):
live = np.asarray(response_body["face"]["confidence"])
assert live.shape == (n_frames,)
state = np.asarray(response_body["state"]["data"])
assert state.shape == (2, 128)
assert state.shape == (256,)

def test_VitalLens_API_wrong_api_key(request):
config = load_config("vitallens.yaml")
Expand All @@ -194,4 +194,4 @@ def test_VitalLens_API_no_parseable_video(request):
headers = {"x-api-key": api_key}
payload = {"video": "not_parseable"}
response = requests.post(API_URL, headers=headers, json=payload)
assert response.status_code == 400
assert response.status_code == 422
6 changes: 5 additions & 1 deletion vitallens/methods/vitallens.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,11 @@ def process_api_batch(
elif response.status_code == 429:
raise VitalLensAPIQuotaExceededError()
elif response.status_code == 400:
raise VitalLensAPIError("Error occurred in the API. Message: {}".format(response_body['message']))
raise VitalLensAPIError("Parameters missing: {}".format(response_body['message']))
elif response.status_code == 422:
raise VitalLensAPIError("Issue with provided parameters: {}".format(response_body['message']))
elif response.status_code == 500:
raise VitalLensAPIError("Error occurred in the API: {}".format(response_body['message']))
else:
raise Exception("Error {}: {}".format(response.status_code, response_body['message']))
# Parse response
Expand Down

0 comments on commit 334b192

Please sign in to comment.