Complain if API response is not JSON (#40966)

pull/40974/head
Nathaniel Case 7 years ago committed by GitHub
parent da4ff18406
commit 91fd98a2bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -34,7 +34,11 @@ class HttpApi:
headers = {'Content-Type': 'application/json-rpc'}
response = self.connection.send('/command-api', request, headers=headers, method='POST')
response = json.loads(to_text(response.read()))
response_text = to_text(response.read())
try:
response = json.loads(response_text)
except ValueError:
raise ConnectionError('Response was not valid JSON, got {0}'.format(response_text))
results = handle_response(response)
if self._become:

@ -29,7 +29,12 @@ class HttpApi:
headers = {'Content-Type': 'application/json'}
response = self.connection.send('/ins', request, headers=headers, method='POST')
response = json.loads(to_text(response.read()))
response_text = to_text(response.read())
try:
response = json.loads(response_text)
except ValueError:
raise ConnectionError('Response was not valid JSON, got {0}'.format(response_text))
results = handle_response(response)
if self._become:

Loading…
Cancel
Save