Skip to content

Commit 00b18e6

Browse files
authored
Merge pull request #98 from Aidbox/base-fhir-error-handling-revert
Revert #97
2 parents 37e4e65 + eef91a7 commit 00b18e6

File tree

5 files changed

+9
-55
lines changed

5 files changed

+9
-55
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
## 0.2.1
1+
## 0.2.2
2+
3+
- Revert BaseFHIRError exceptions from fhir-py in operation handlers b
4+
5+
6+
## 0.2.1 (yanked)
27

38
- Handle BaseFHIRError exceptions from fhir-py in operation handlers
49

aidbox_python_sdk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__title__ = "aidbox-python-sdk"
2-
__version__ = "0.2.1"
2+
__version__ = "0.2.2"
33
__author__ = "beda.software"
44
__license__ = "None"
55
__copyright__ = "Copyright 2024 beda.software"

aidbox_python_sdk/handlers.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import asyncio
2-
import json
32
import logging
43
from typing import Any
54

65
from aiohttp import web
7-
from fhirpy.base.exceptions import BaseFHIRError, OperationOutcome
6+
from fhirpy.base.exceptions import OperationOutcome
87

98
from . import app_keys as ak
109

@@ -49,12 +48,6 @@ async def operation(request: web.Request, data: dict[str, Any]):
4948
return result
5049
except OperationOutcome as exc:
5150
return web.json_response(exc.resource, status=422)
52-
except BaseFHIRError as exc:
53-
try:
54-
payload = json.loads(str(exc))
55-
return web.json_response(payload, status=422)
56-
except (json.JSONDecodeError, TypeError):
57-
return web.Response(text=str(exc), status=422, content_type="text/plain")
5851

5952

6053
TYPES = {

main.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import asyncio
2-
import json
32
import logging
43
from datetime import datetime
54

65
import coloredlogs
76
from aiohttp import web
8-
from fhirpy.base.exceptions import BaseFHIRError, OperationOutcome
7+
from fhirpy.base.exceptions import OperationOutcome
98
from sqlalchemy.sql.expression import select
109

1110
from aidbox_python_sdk.db import DBProxy
@@ -161,34 +160,3 @@ async def observation_custom_op(operation, request):
161160
)
162161
async def operation_outcome_test_op(operation, request):
163162
raise OperationOutcome(reason="test reason")
164-
165-
166-
@sdk.operation(
167-
["POST"],
168-
["$base-fhir-error-json-test"],
169-
)
170-
async def base_fhir_error_json_test_op(operation, request):
171-
raise BaseFHIRError(
172-
json.dumps(
173-
{
174-
"resourceType": "OperationOutcome",
175-
"id": "not-found",
176-
"text": {"status": "generated", "div": "Resource Patient/id not found"},
177-
"issue": [
178-
{
179-
"severity": "fatal",
180-
"code": "not-found",
181-
"diagnostics": "Resource Patient/id not found",
182-
}
183-
],
184-
}
185-
)
186-
)
187-
188-
189-
@sdk.operation(
190-
["POST"],
191-
["$base-fhir-error-text-test"],
192-
)
193-
async def base_fhir_error_text_test_op(operation, request):
194-
raise BaseFHIRError("plain")

tests/test_sdk.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,6 @@ async def test_aidbox_db_fixture(client, aidbox_db: DBProxy, safe_db):
192192
assert app_ids == [{"id": "app-test"}]
193193

194194

195-
async def test_operation_base_fhir_error_json_test_op(aidbox_client):
196-
with pytest.raises(OperationOutcome) as exc:
197-
await aidbox_client.execute("/$base-fhir-error-json-test")
198-
assert exc.value.resource.get("issue")[0].get("diagnostics") == "Resource Patient/id not found"
199-
200-
201-
async def test_operation_base_fhir_error_text_test_op(aidbox_client):
202-
with pytest.raises(OperationOutcome) as exc:
203-
await aidbox_client.execute("/$base-fhir-error-text-test")
204-
assert exc.value.resource.get("issue")[0].get("diagnostics") == "plain"
205-
206-
207195
async def test_operation_outcome_test_op(aidbox_client):
208196
with pytest.raises(OperationOutcome) as exc:
209197
await aidbox_client.execute("/$operation-outcome-test")

0 commit comments

Comments
 (0)