Handle non-JSON return values
This commit is contained in:
parent
0b5fd3a2cf
commit
b7e3210631
|
@ -157,12 +157,14 @@ def remote_config(module, method='GET', config=None, result=None, device=None,
|
||||||
|
|
||||||
try:
|
try:
|
||||||
content = resp.read()
|
content = resp.read()
|
||||||
return json.loads(content)
|
except AttributeError:
|
||||||
except (AttributeError, json.decoder.JSONDecodeError):
|
|
||||||
result['content'] = info.pop('body', '')
|
result['content'] = info.pop('body', '')
|
||||||
module.fail_json(msg='Error occured while reading response', **result)
|
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):
|
def get_device(module, device=None):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user