Skip to content

Commit d78978e

Browse files
authored
Handle JSON and non-JSON BaseFHIRError
1 parent bd1b7dd commit d78978e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

aidbox_python_sdk/handlers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ async def operation(request: web.Request, data: dict[str, Any]):
4949
except OperationOutcome as exc:
5050
return web.json_response(exc.resource, status=422)
5151
except BaseFHIRError as exc:
52-
return web.json_response(str(exc), status=422)
52+
try:
53+
payload = json.loads(str(exc))
54+
return web.json_response(payload, status=422)
55+
except (json.JSONDecodeError, TypeError):
56+
return web.Response(text=str(exc), status=422, content_type='text/plain')
5357

5458

5559
TYPES = {

0 commit comments

Comments
 (0)