Handle non-JSON return values

This commit is contained in:
Peter Šurda 2024-04-22 16:20:30 +08:00
parent 0b5fd3a2cf
commit b7e3210631
Signed by untrusted user: PeterSurda
GPG Key ID: 3E47497CF67ABB95

View File

@ -157,12 +157,14 @@ def remote_config(module, method='GET', config=None, result=None, device=None,
try:
content = resp.read()
return json.loads(content)
except (AttributeError, json.decoder.JSONDecodeError):
except AttributeError:
result['content'] = info.pop('body', '')
module.fail_json(msg='Error occured while reading response', **result)
return {} # not reachable but prevents linter complaints
try:
return json.loads(content)
except json.decoder.JSONDecodeError:
return {'content': content}
def get_device(module, device=None):