1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Complain if API response is not JSON (#40966)

This commit is contained in:
Nathaniel Case 2018-05-31 13:20:17 -04:00 committed by GitHub
parent da4ff18406
commit 91fd98a2bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View file

@ -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:

View file

@ -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: