Skip to content

Commit a28aeea

Browse files
committed
Better response error messages
1 parent ac176e4 commit a28aeea

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,4 @@ v0.2.8b0:
115115
2026-05-02 -- Documentation
116116
v0.2.8b1:
117117
2026-05-02 -- Versioning updates
118+
2026-05-19 -- Better response error messages

hapiclient/util.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -330,30 +330,29 @@ def get_full_class_name(obj):
330330

331331
c = " If problem persists, a contact email for the server may be listed "
332332
c = c + "at http://hapi-server.org/servers/"
333-
msg = '';
333+
msg = ''
334334
try:
335335
http = urllib3.PoolManager()
336336
res = http.request('GET', url, preload_content=False, retries=2)
337337
if res.status != 200:
338+
msgo = "Problem with " + url + \
339+
". Server responded with non-200 HTTP status (" + \
340+
str(res.status) + ") "
338341
try:
339342
jres = load(res)
340-
except Exception as e:
341-
msg = "Problem with " + url + \
342-
". Server responded with non-200 HTTP status (" \
343-
+ str(res.status) + \
344-
") and an invalid JSON in response body." + c
345-
346-
if msg == '' and 'status' in jres:
347-
if 'message' in jres['status']:
348-
msg = '%s\n' % (jres['status']['message'])
343+
except Exception:
344+
msg = msgo + "and invalid JSON in response body." + c
349345

350346
if msg == '':
351-
msg = "Problem with " + url + \
352-
". Server responded with non-200 HTTP status (" + \
353-
str(res.status) + \
354-
") but no JSON without HAPI error message in response body." + c
355-
356-
raise HAPIError
347+
if 'status' in jres:
348+
if 'message' in jres['status']:
349+
msg = msgo + 'and error message: %s\n' % (jres['status']['message'])
350+
else:
351+
msg = msgo + "and no error message in status element of response body." + c
352+
else:
353+
msg = msgo + "and JSON without HAPI status in response body." + c
354+
355+
raise HAPIError(msg)
357356

358357
except HAPIError:
359358
error(msg)

0 commit comments

Comments
 (0)