Merge pull request #147 from StrayLightning/master

Check explicitly for a 500 response from the server with no response content
pull/149/head v2.4.83
Raphaël Vinot 2017-12-06 10:41:21 +01:00 committed by GitHub
commit 7db4dcfa22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -223,13 +223,16 @@ class PyMISP(object):
"""Check if the response from the server is not an unexpected error"""
errors = []
if response.status_code >= 500:
errors.append(response.json())
logger.critical('Something bad happened on the server-side: {}'.format(response.json()))
if len(response.content) == 0:
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:
to_return = response.json()
except ValueError:
# 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)):
to_return = {'response': to_return}