Skip to content

Commit

Permalink
much more fine grained error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoca committed Jun 6, 2016
1 parent 261b0af commit 2a984bb
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/ansible/galaxy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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
Expand Down Expand Up @@ -109,12 +110,21 @@ def _get_server_api_version(self):
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):
Expand Down

0 comments on commit 2a984bb

Please sign in to comment.