Skip to content

Commit 82389e8

Browse files
committed
Handle media type of failure response messages
1 parent 35a0540 commit 82389e8

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/dicomweb_client/api.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,8 +1442,14 @@ def serve_data_chunks(data):
14421442
if not response.ok:
14431443
logger.warning('storage was not successful for all instances')
14441444
payload = response.content
1445-
tree = ET.fromstring(payload)
1446-
dataset = _load_xml_dataset(tree)
1445+
content_type = response.headers['Content-Type']
1446+
if content_type in ('application/dicom+json', 'application/json', ):
1447+
dataset = load_json_dataset(payload)
1448+
elif content_type in ('application/dicom+xml', 'application/xml', ):
1449+
tree = ET.fromstring(payload)
1450+
dataset = _load_xml_dataset(tree)
1451+
else:
1452+
raise ValueError('Response message has unexpected media type.')
14471453
failed_sop_sequence = getattr(dataset, 'FailedSOPSequence', [])
14481454
for failed_sop_item in failed_sop_sequence:
14491455
logger.error(
@@ -1487,11 +1493,10 @@ def _http_post_multipart_application_dicom(
14871493
headers={'Content-Type': content_type}
14881494
)
14891495
if response.content:
1490-
if (response.headers['Content-Type'] == 'application/dicom+json' or
1491-
response.headers['Content-Type'] == 'application/json'):
1496+
content_type = response.headers['Content-Type']
1497+
if content_type in ('application/dicom+json', 'application/json', ):
14921498
return load_json_dataset(response.json())
1493-
elif (response.headers['Content-Type'] == 'application/dicom+xml' or
1494-
response.headers['Content-Type'] == 'application/xml'):
1499+
elif content_type in ('application/dicom+xml', 'application/xml', ):
14951500
tree = ET.fromstring(response.content)
14961501
return _load_xml_dataset(tree)
14971502
return None

0 commit comments

Comments
 (0)