mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 01:47:35 -02:30
Add new CollectionsParserError class for exceptions
This commit is contained in:
@@ -35,8 +35,7 @@ import traceback
|
|||||||
|
|
||||||
from ansible.module_utils._text import to_native
|
from ansible.module_utils._text import to_native
|
||||||
from ansible.module_utils.urls import urllib_error, ConnectionError, socket, httplib
|
from ansible.module_utils.urls import urllib_error, ConnectionError, socket, httplib
|
||||||
from ansible.module_utils.urls import Request # noqa (the sole purpose of this line is to allow for import into other files)
|
from ansible.module_utils.urls import Request # noqa
|
||||||
from ansible.errors import AnsibleParserError
|
|
||||||
|
|
||||||
TOWER_CLI_IMP_ERR = None
|
TOWER_CLI_IMP_ERR = None
|
||||||
try:
|
try:
|
||||||
@@ -63,14 +62,14 @@ def make_request(request_handler, tower_url):
|
|||||||
# If Tower gives a readable error message, display that message to the user.
|
# If Tower gives a readable error message, display that message to the user.
|
||||||
if callable(getattr(e, 'read', None)):
|
if callable(getattr(e, 'read', None)):
|
||||||
n_error_msg += ' with message: {err_msg}'.format(err_msg=to_native(e.read()))
|
n_error_msg += ' with message: {err_msg}'.format(err_msg=to_native(e.read()))
|
||||||
raise AnsibleParserError(n_error_msg)
|
raise CollectionsParserError(n_error_msg)
|
||||||
|
|
||||||
# Attempt to parse JSON.
|
# Attempt to parse JSON.
|
||||||
try:
|
try:
|
||||||
return json.loads(response.read())
|
return json.loads(response.read())
|
||||||
except (ValueError, TypeError) as e:
|
except (ValueError, TypeError) as e:
|
||||||
# If the JSON parse fails, print the ValueError
|
# If the JSON parse fails, print the ValueError
|
||||||
raise AnsibleParserError('Failed to parse json from host: {err}'.format(err=to_native(e)))
|
raise CollectionsParserError('Failed to parse json from host: {err}'.format(err=to_native(e)))
|
||||||
|
|
||||||
|
|
||||||
def tower_auth_config(module):
|
def tower_auth_config(module):
|
||||||
@@ -142,3 +141,7 @@ class TowerModule(AnsibleModule):
|
|||||||
if not HAS_TOWER_CLI:
|
if not HAS_TOWER_CLI:
|
||||||
self.fail_json(msg=missing_required_lib('ansible-tower-cli'),
|
self.fail_json(msg=missing_required_lib('ansible-tower-cli'),
|
||||||
exception=TOWER_CLI_IMP_ERR)
|
exception=TOWER_CLI_IMP_ERR)
|
||||||
|
|
||||||
|
|
||||||
|
class CollectionsParserError(Exception):
|
||||||
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user