summaryrefslogtreecommitdiff
path: root/lib/ansible/galaxy/api.py
diff options
context:
space:
mode:
authorBrian Coca <brian.coca+git@gmail.com>2016-06-06 11:47:45 -0400
committerBrian Coca <brian.coca+git@gmail.com>2016-06-06 11:48:16 -0400
commit2a984bbc981554560bf91645facaf535da803738 (patch)
treeddaeb5646884561649789cbdc4327c8b263d49b7 /lib/ansible/galaxy/api.py
parent261b0af15aa184780c50aa9ba36327d558d7c784 (diff)
downloadansible-2a984bbc981554560bf91645facaf535da803738.tar.gz
much more fine grained error messages
fixes #16039
Diffstat (limited to 'lib/ansible/galaxy/api.py')
-rw-r--r--lib/ansible/galaxy/api.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/ansible/galaxy/api.py b/lib/ansible/galaxy/api.py
index de3c5d293c..0d1eb0fccd 100644
--- a/lib/ansible/galaxy/api.py
+++ b/lib/ansible/galaxy/api.py
@@ -33,6 +33,7 @@ import ansible.constants as C
from ansible.errors import AnsibleError
from ansible.module_utils.urls import open_url
from ansible.galaxy.token import GalaxyToken
+from ansible.utils.unicode import to_str
try:
from __main__ import display
@@ -109,12 +110,21 @@ class GalaxyAPI(object):
Fetches the Galaxy API current version to ensure
the API server is up and reachable.
"""
+ url = '%s/api/' % self._api_server
try:
- url = '%s/api/' % self._api_server
- data = json.load(open_url(url, validate_certs=self._validate_certs))
- return data['current_version']
+ return_data =open_url(url, validate_certs=self._validate_certs)
except Exception as e:
- raise AnsibleError("The API server (%s) is not responding, please try again later" % url)
+ raise AnsibleError("Failed to get data from the API server (%s): %s " % (url, to_str(e)))
+
+ try:
+ data = json.load(return_data)
+ except Exception as e:
+ raise AnsibleError("Could not process data from the API server (%s): %s " % (url, to_str(e)))
+
+ if not 'current_version' in data:
+ raise AnsibleError("missing required 'current_version' from server response (%s)" % url)
+
+ return data['current_version']
@g_connect
def authenticate(self, github_token):