diff options
author | Johannes Zellner <johannes@nebulon.de> | 2015-09-08 14:23:54 +0200 |
---|---|---|
committer | Johannes Zellner <johannes@nebulon.de> | 2015-09-08 14:23:54 +0200 |
commit | b9ad5d9155a65125f83071b409b4193ee97ce9d8 (patch) | |
tree | 63cb58445fc0656426f3c23b184475f79c499dfc /cli | |
parent | 8558946083675e4ae03f30c7d7799309a3901afa (diff) | |
download | Surfer-b9ad5d9155a65125f83071b409b4193ee97ce9d8.tar.gz Surfer-b9ad5d9155a65125f83071b409b4193ee97ce9d8.tar.zst Surfer-b9ad5d9155a65125f83071b409b4193ee97ce9d8.zip |
Improve error handling on login
Diffstat (limited to 'cli')
-rw-r--r-- | cli/actions.js | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/cli/actions.js b/cli/actions.js index c8b5c33..bdfc066 100644 --- a/cli/actions.js +++ b/cli/actions.js | |||
@@ -53,20 +53,24 @@ function login(uri) { | |||
53 | var tmp = url.parse(uri); | 53 | var tmp = url.parse(uri); |
54 | if (!tmp.host) tmp = url.parse('https://' + uri); | 54 | if (!tmp.host) tmp = url.parse('https://' + uri); |
55 | 55 | ||
56 | var server = 'https://' + tmp.host; | 56 | var server = tmp.protocol + '//' + tmp.host; |
57 | 57 | ||
58 | console.log('Using server', server); | 58 | console.log('Using server', server.bold); |
59 | 59 | ||
60 | var username = readlineSync.question('Username: ', { hideEchoBack: false }); | 60 | var username = readlineSync.question('Username: ', { hideEchoBack: false }); |
61 | var password = readlineSync.question('Password: ', { hideEchoBack: true }); | 61 | var password = readlineSync.question('Password: ', { hideEchoBack: true }); |
62 | 62 | ||
63 | superagent.get(server + API + '/').query({ username: username, password: password }).end(function (error, result) { | 63 | superagent.get(server + API + '/').query({ username: username, password: password }).end(function (error, result) { |
64 | if (error && error.code === 'ENOTFOUND') { | 64 | if (error && error.code === 'ENOTFOUND') { |
65 | console.log('No such server %s'.red, server); | 65 | console.log('No such server %s'.red, server.bold); |
66 | process.exit(1); | ||
67 | } | ||
68 | if (error.code) { | ||
69 | console.log('Failed to connect to server %s'.red, server.bold, error.code); | ||
66 | process.exit(1); | 70 | process.exit(1); |
67 | } | 71 | } |
68 | if (result.status === 401) { | 72 | if (result.status === 401) { |
69 | console.log('Login failed.'); | 73 | console.log('Login failed.'.red); |
70 | process.exit(1); | 74 | process.exit(1); |
71 | } | 75 | } |
72 | 76 | ||
@@ -78,7 +82,7 @@ function login(uri) { | |||
78 | 82 | ||
79 | gQuery = { username: username, password: password }; | 83 | gQuery = { username: username, password: password }; |
80 | 84 | ||
81 | console.log('Done'.green); | 85 | console.log('Ok'.green); |
82 | }); | 86 | }); |
83 | } | 87 | } |
84 | 88 | ||