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:
parent
da4ff18406
commit
91fd98a2bd
2 changed files with 11 additions and 2 deletions
|
@ -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…
Reference in a new issue