Skip to content

Commit

Permalink
Improve orchestration error messages (#2661)
Browse files Browse the repository at this point in the history
* Catch orchestration errors and fix string concatenation bug

* add test for orchestration errors

* remove unused import

* [pre-commit.ci] auto fixes from pre-commit hooks

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
1 parent dc691e2 commit 554dea6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
23 changes: 22 additions & 1 deletion containers/orchestration/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from fastapi import Body
from fastapi import File
from fastapi import Form
from fastapi import HTTPException
from fastapi import Response
from fastapi import status
from fastapi import UploadFile
Expand Down Expand Up @@ -317,7 +318,27 @@ async def apply_workflow_to_message(
"rr_data": rr_content,
}
wf_span.add_event("sending params to `call_apis`")
response, responses = await call_apis(config=processing_config, input=api_input)
try:
response, responses = await call_apis(
config=processing_config, input=api_input
)
except HTTPException as error:
# These exceptions are purposefully created in call_apis to surface service errors
raise error
except Exception as error:
# Handle internal exceptions
wf_span.record_exception(error)
return Response(
content=json.dumps(
{
"message": f"Orchestration service error: {error.__str__()}",
"processed_values": {},
}
),
media_type="application/json",
status_code=500,
)

wf_span.add_event(
"`call_apis` responded with computed result",
attributes={"return_code": response.status_code},
Expand Down
6 changes: 2 additions & 4 deletions containers/orchestration/app/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,8 @@ async def call_apis(
call_span.record_exception(
HTTPException, attributes={"status_code": 400}
)
error_detail = (
f"Service {service} completed, but orchestration cannot continue "
)
+f"{service_response.msg_content}"
error_detail = f"Service {service} completed, but orchestration cannot continue: {service_response.msg_content}"

call_span.set_status(StatusCode(2), error_detail)
raise HTTPException(
status_code=400,
Expand Down
18 changes: 18 additions & 0 deletions containers/orchestration/tests/test_process_message_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,24 @@ def test_process_message_success(patched_post_request):
assert actual_response.status_code == 200


@mock.patch("app.main.call_apis", side_effect=Exception("Fake Exception"))
def test_process_message_orchestration_error(patched_call_apis):
message = open(Path(__file__).parent / "assets" / "hl7_with_msh_3_set.hl7").read()
request = {
"message_type": "elr",
"data_type": "hl7",
"config_file_name": "sample-orchestration-config.json",
"message": message,
}

actual_response = client.post("/process-message", json=request)
assert actual_response.status_code == 500
assert actual_response.json() == {
"message": "Orchestration service error: Fake Exception",
"processed_values": {},
}


@mock.patch("app.services.post_request")
def test_process_message_fhir_data(patched_post_request):
request = {
Expand Down

0 comments on commit 554dea6

Please sign in to comment.