mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 11:21:25 -07:00
HTTPError can also function as a non-exceptional file-like return value (#14915)
* HTTPError can also function as a non-exceptional file-like return value (the same thing that urlopen() returns) * HTTPError - adding response to info dictionnary * HTTPError - adding response to info dictionnary * HTTPError - adding body response to info dictionnary
This commit is contained in:
parent
f296d74329
commit
4647e8b74e
1 changed files with 5 additions and 1 deletions
|
@ -897,7 +897,11 @@ def fetch_url(module, url, data=None, headers=None, method=None,
|
||||||
except (ConnectionError, ValueError), e:
|
except (ConnectionError, ValueError), e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
except urllib2.HTTPError, e:
|
except urllib2.HTTPError, e:
|
||||||
info.update(dict(msg=str(e), status=e.code, **e.info()))
|
try:
|
||||||
|
body = e.read()
|
||||||
|
except AttributeError:
|
||||||
|
body = ''
|
||||||
|
info.update(dict(msg=str(e), status=e.code, body=body, **e.info()))
|
||||||
except urllib2.URLError, e:
|
except urllib2.URLError, e:
|
||||||
code = int(getattr(e, 'code', -1))
|
code = int(getattr(e, 'code', -1))
|
||||||
info.update(dict(msg="Request failed: %s" % str(e), status=code))
|
info.update(dict(msg="Request failed: %s" % str(e), status=code))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue