Skip to content

Commit

Permalink
HTTPError can also function as a non-exceptional file-like return val…
Browse files Browse the repository at this point in the history
…ue (ansible#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
  • Loading branch information
job-so authored and jimi-c committed Apr 25, 2016
1 parent f296d74 commit 4647e8b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/ansible/module_utils/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,11 @@ def fetch_url(module, url, data=None, headers=None, method=None,
except (ConnectionError, ValueError), e:
module.fail_json(msg=str(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:
code = int(getattr(e, 'code', -1))
info.update(dict(msg="Request failed: %s" % str(e), status=code))
Expand Down

0 comments on commit 4647e8b

Please sign in to comment.