Skip to content

Commit

Permalink
feat: update error message
Browse files Browse the repository at this point in the history
  • Loading branch information
jtyoung84 committed Feb 1, 2024
1 parent 306d4bf commit b71018d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
8 changes: 5 additions & 3 deletions src/aind_data_transfer_service/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def validate_csv(request: Request):
# Construct hpc job setting most of the vars from the env
basic_jobs.append(job.model_dump_json())
except Exception as e:
errors.append(f"{e.__class__}: {e.args}")
errors.append(f"{e.__class__.__name__}{e.args}")
message = "There were errors" if len(errors) > 0 else "Valid Data"
status_code = 406 if len(errors) > 0 else 200
content = {
Expand Down Expand Up @@ -106,7 +106,9 @@ async def submit_basic_jobs(request: Request):
hpc_job = HpcJobConfigs(basic_upload_job_configs=basic_upload_job)
hpc_jobs.append(hpc_job)
except Exception as e:
parsing_errors.append(f"Error parsing {job}: {e.__class__}")
parsing_errors.append(
f"Error parsing {job}: {e.__class__.__name__}"
)
if parsing_errors:
status_code = 406
message = "There were errors parsing the basic job configs"
Expand All @@ -126,7 +128,7 @@ async def submit_basic_jobs(request: Request):
# Add pause to stagger job requests to the hpc
await sleep(0.2)
except Exception as e:
logging.error(f"{e.__class__}: {e.args}")
logging.error(f"{e.__class__.__name__}{e.args}")
hpc_errors.append(
f"Error processing "
f"{hpc_job.basic_upload_job_configs.s3_prefix}"
Expand Down
19 changes: 4 additions & 15 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,8 @@ def test_submit_jobs_malformed_json(
"responses": [],
"errors": [
(
'Error parsing {"malformed_key": "val"}: '
"<class 'pydantic_core._pydantic_core"
".ValidationError'>"
'Error parsing {"malformed_key": "val"}:'
" ValidationError"
)
],
},
Expand Down Expand Up @@ -230,12 +229,7 @@ def test_validate_malformed_csv(self):
response = client.post(url="/api/validate_csv", files=files)
self.assertEqual(response.status_code, 406)
self.assertEqual(
[
(
"<class 'AttributeError'>:"
" ('Unknown Modality: WRONG_MODALITY_HERE',)"
)
],
[("AttributeError('Unknown Modality: WRONG_MODALITY_HERE',)")],
response.json()["data"]["errors"],
)

Expand All @@ -250,12 +244,7 @@ def test_validate_malformed_xlsx(self):
response = client.post(url="/api/validate_csv", files=files)
self.assertEqual(response.status_code, 406)
self.assertEqual(
[
(
"<class 'AttributeError'>:"
" ('Unknown Modality: WRONG_MODALITY_HERE',)"
)
],
[("AttributeError('Unknown Modality: WRONG_MODALITY_HERE',)")],
response.json()["data"]["errors"],
)

Expand Down

0 comments on commit b71018d

Please sign in to comment.