mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
httpapi: let httpapi plugin handle HTTPErrors other than 401 (#43436)
* Hold httpapi response in BytesIO * Let httpapi plugin deal with HTTP codes if it wants * Python 3.5 won't json.loads() bytes * Don't modify headers passed to send * Move code handling back to send() but let httpapi plugin have a say on how it happens
This commit is contained in:
parent
65772ede26
commit
a3385a60b4
4 changed files with 62 additions and 23 deletions
|
@ -30,13 +30,16 @@ class HttpApi(HttpApiBase):
|
|||
request = request_builder(data, output)
|
||||
headers = {'Content-Type': 'application/json-rpc'}
|
||||
|
||||
response, response_text = self.connection.send('/command-api', request, headers=headers, method='POST')
|
||||
try:
|
||||
response_text = json.loads(response_text)
|
||||
except ValueError:
|
||||
raise ConnectionError('Response was not valid JSON, got {0}'.format(response_text))
|
||||
response, response_data = self.connection.send('/command-api', request, headers=headers, method='POST')
|
||||
|
||||
results = handle_response(response_text)
|
||||
try:
|
||||
response_data = json.loads(to_text(response_data.getvalue()))
|
||||
except ValueError:
|
||||
raise ConnectionError('Response was not valid JSON, got {0}'.format(
|
||||
to_text(response_data.getvalue())
|
||||
))
|
||||
|
||||
results = handle_response(response_data)
|
||||
|
||||
if self._become:
|
||||
results = results[1:]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue