mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Ensure uri module always returns status even on failure (#56240)
- Also return url and update docs for other values to indicate they are only returned on success. - Add integration tests - Use info variable for common return values - Use -1 as default status rather than None. This is lines up with with existing code in urls.py - Add unit tests to ensure status and url are returned on failure
This commit is contained in:
@@ -1429,7 +1429,7 @@ def fetch_url(module, url, data=None, headers=None, method=None,
|
||||
cookies = cookiejar.LWPCookieJar()
|
||||
|
||||
r = None
|
||||
info = dict(url=url)
|
||||
info = dict(url=url, status=-1)
|
||||
try:
|
||||
r = open_url(url, data=data, headers=headers, method=method,
|
||||
use_proxy=use_proxy, force=force, last_mod_time=last_mod_time, timeout=timeout,
|
||||
@@ -1471,11 +1471,11 @@ def fetch_url(module, url, data=None, headers=None, method=None,
|
||||
except NoSSLError as e:
|
||||
distribution = get_distribution()
|
||||
if distribution is not None and distribution.lower() == 'redhat':
|
||||
module.fail_json(msg='%s. You can also install python-ssl from EPEL' % to_native(e))
|
||||
module.fail_json(msg='%s. You can also install python-ssl from EPEL' % to_native(e), **info)
|
||||
else:
|
||||
module.fail_json(msg='%s' % to_native(e))
|
||||
module.fail_json(msg='%s' % to_native(e), **info)
|
||||
except (ConnectionError, ValueError) as e:
|
||||
module.fail_json(msg=to_native(e))
|
||||
module.fail_json(msg=to_native(e), **info)
|
||||
except urllib_error.HTTPError as e:
|
||||
try:
|
||||
body = e.read()
|
||||
|
||||
@@ -314,7 +314,7 @@ RETURN = r'''
|
||||
# The return information includes all the HTTP headers in lower-case.
|
||||
elapsed:
|
||||
description: The number of seconds that elapsed while performing the download
|
||||
returned: always
|
||||
returned: on success
|
||||
type: int
|
||||
sample: 23
|
||||
msg:
|
||||
@@ -324,7 +324,7 @@ msg:
|
||||
sample: OK (unknown bytes)
|
||||
redirected:
|
||||
description: Whether the request was redirected
|
||||
returned: always
|
||||
returned: on success
|
||||
type: bool
|
||||
sample: false
|
||||
status:
|
||||
|
||||
Reference in New Issue
Block a user