Skip to content

Commit 59f5855

Browse files
authored
Merge pull request #86 from ConsenSys/better-401-msg
Better error messages for HTTP 401...
2 parents 7538061 + 37924eb commit 59f5855

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

lib/requester.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,28 @@ exports.do = (input, accessToken, apiUrl) => {
2323

2424
/* eslint-disable prefer-promise-reject-errors */
2525
if (res.statusCode < 200 || res.statusCode > 299) {
26-
const errMsg = `Failed in retrieving analysis response: ${res.error} (HTTP status code: ${res.status})`
26+
const errMsg = `Failed in retrieving analysis response: ${res.statusMessage} (HTTP status code: ${res.statusCode})`
27+
// console.log(errMsg)
2728
if (res.statusCode === 401) {
28-
reject('MythX credentials are incorrect.')
29+
/* For now, try to provide better 401 error messages. Right now, all we are ever getting
30+
back seems to be "Unauthorized". But Remi reports that somewhere in the back end
31+
the other two are set, even if right now they don't get passed through.
32+
*/
33+
switch (res.statusMessage) {
34+
case 'Unauthorized':
35+
reject('MythX credentials are incorrect.')
36+
break
37+
case 'Challenge expired':
38+
reject('The token for the initial JWT login has expired; use the refresh token to get a longer-expiring access token.')
39+
break
40+
case 'Invalid challenge':
41+
reject('MythX credentials are incorrect.')
42+
break
43+
default:
44+
// The hope is that if the message is not one of the above -- and that will happen sometime in the future --
45+
// then we have something useful that can be passed back untouched.
46+
reject(res.statusMessage)
47+
}
2948
return
3049
} else if (res.statusCode === 400) {
3150
reject(res.body.error)

0 commit comments

Comments
 (0)