mirror of https://github.com/MISP/PyMISP
Merge pull request #147 from StrayLightning/master
Check explicitly for a 500 response from the server with no response contentpull/149/head v2.4.83
commit
7db4dcfa22
|
@ -223,13 +223,16 @@ class PyMISP(object):
|
||||||
"""Check if the response from the server is not an unexpected error"""
|
"""Check if the response from the server is not an unexpected error"""
|
||||||
errors = []
|
errors = []
|
||||||
if response.status_code >= 500:
|
if response.status_code >= 500:
|
||||||
errors.append(response.json())
|
if len(response.content) == 0:
|
||||||
logger.critical('Something bad happened on the server-side: {}'.format(response.json()))
|
raise PyMISPError('Something bad happened on the server-side, but there was no response content to be decoded')
|
||||||
|
else:
|
||||||
|
errors.append(response.json())
|
||||||
|
logger.critical('Something bad happened on the server-side: {}'.format(response.json()))
|
||||||
try:
|
try:
|
||||||
to_return = response.json()
|
to_return = response.json()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# It the server didn't return a JSON blob, we've a problem.
|
# It the server didn't return a JSON blob, we've a problem.
|
||||||
raise PyMISPError('Unknown error (something is very broken server-side: {}'.format(response.text))
|
raise PyMISPError('Unknown error (something is very broken server-side: {})'.format(response.text))
|
||||||
|
|
||||||
if isinstance(to_return, (list, str)):
|
if isinstance(to_return, (list, str)):
|
||||||
to_return = {'response': to_return}
|
to_return = {'response': to_return}
|
||||||
|
|
Loading…
Reference in New Issue