mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-03 09:13:12 +00:00
Complain if API response is not JSON (#40966)
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user