Skip to content

Commit 75dc2b9

Browse files
committed
Merge pull request #444 from tombh/client-feedback-for-unresponsive-controller
Catch ConnectionError in client and return human friendly message. Travis flaked out on this one and I can't get it to try again. LGTM, thanks Tom!
2 parents 3146375 + bf4de12 commit 75dc2b9

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

client/deis.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,6 +2070,28 @@ def parse_args(cmd):
20702070
return cmd, help_flag
20712071

20722072

2073+
def _dispatch_cmd(method, args):
2074+
try:
2075+
method(args)
2076+
except requests.exceptions.ConnectionError as err:
2077+
print("Couldn't connect to the Deis Controller. Make sure that the Controller URI is \
2078+
correct and the server is running.")
2079+
sys.exit(1)
2080+
except EnvironmentError as err:
2081+
raise DocoptExit(err.message)
2082+
except ResponseError as err:
2083+
resp = err.message
2084+
print('{} {}'.format(resp.status_code, resp.reason))
2085+
try:
2086+
msg = resp.json()
2087+
if 'detail' in msg:
2088+
msg = "Detail:\n{}".format(msg['detail'])
2089+
except:
2090+
msg = resp.text
2091+
print(msg)
2092+
sys.exit(1)
2093+
2094+
20732095
def main():
20742096
"""
20752097
Create a client, parse the arguments received on the command line, and
@@ -2097,21 +2119,7 @@ def main():
20972119
if 'Usage: ' in docstring:
20982120
args.update(docopt(docstring))
20992121
# dispatch the CLI command
2100-
try:
2101-
method(args)
2102-
except EnvironmentError as err:
2103-
raise DocoptExit(err.message)
2104-
except ResponseError as err:
2105-
resp = err.message
2106-
print('{} {}'.format(resp.status_code, resp.reason))
2107-
try:
2108-
msg = resp.json()
2109-
if 'detail' in msg:
2110-
msg = "Detail:\n{}".format(msg['detail'])
2111-
except:
2112-
msg = resp.text
2113-
print(msg)
2114-
sys.exit(1)
2122+
_dispatch_cmd(method, args)
21152123

21162124

21172125
if __name__ == '__main__':

0 commit comments

Comments
 (0)