Closed BSVogler closed 2 years ago
Hi @BSVogler! Thanks for the contribution.
Related issues: https://github.com/beda-software/fhir-py/issues/53, https://github.com/beda-software/fhir-py/issues/50.
Parsing json should be done closer to the code that raises OperationOutcome: https://github.com/beda-software/fhir-py/blob/0a22b8c358241ed0fca5dd427a28a6dabca12ef4/fhirpy/base/lib.py#L110 https://github.com/beda-software/fhir-py/blob/0a22b8c358241ed0fca5dd427a28a6dabca12ef4/fhirpy/base/lib.py#L133 https://github.com/beda-software/fhir-py/blob/0a22b8c358241ed0fca5dd427a28a6dabca12ef4/fhirpy/base/lib.py#L329 https://github.com/beda-software/fhir-py/blob/0a22b8c358241ed0fca5dd427a28a6dabca12ef4/fhirpy/base/lib.py#L387
And I like your idea to fetch the error from issue just using the code:
try:
await resource.save()
except OperationOutcome as e:
print(e)
but the source OperationOutcome resource should be stored in OperationOutcome in attribute, for example as OperationOutcome.data, to give an ability to return it further or extract some details in the app's code:
try:
await resource.save()
except OperationOutcome as e:
return web.json_response(e.data)
Both are reasonable suggestions. I will look into this.
We improved fhir server's OperationError response handling in https://github.com/beda-software/fhir-py/commit/f5afe66442a4eac89e6cad62b294d73106ebd7e5.
Now it is accessible via exc.resource:
try:
await resource.save()
except OperationOutcome as exc:
exc.resource # Here is the original OperationOutcome
A typical error may contain addition information like formatted output (HAPI) and it will report as this in sentry:
This change only reports the error message as defined by the standard.