Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #21 from Cox-Automotive/betterLogging
Browse files Browse the repository at this point in the history
[BUGFIX] Better error responses!
  • Loading branch information
amagana3 committed Aug 31, 2020
2 parents a62bc2e + e03fc61 commit 52bf0ff
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/alks-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ var getMessageFromBadResponse = function(results){
return 'Bad response received, please check API URL.';
};

var getMessageFromRefreshToAccess = function(results) {
if (results.body) {
if (results.body.errors) {
return results.body.errors;
}
}
return 'Bad response received, please check API URL.';
}

var log = function(section, msg, options){
if(options.debug){
console.error([ '[', section, ']: ', msg ].join(''));
Expand Down Expand Up @@ -621,11 +630,10 @@ exports.refreshTokenToAccessToken = function(account, token, opts, callback){
}
}, function(err, results){
if(err){
// [AM] - This is when we get a 500, which is (in ALKS Core) a bad refresh token. Should pass this error to the CLI.
return callback("Error: Refresh token expired. Please try to use the logout2fa and login2fa commands.");
return callback(err);
}
else if(results.statusCode !== 200){
return callback(new Error(getMessageFromBadResponse(results)));
return callback(new Error(getMessageFromRefreshToAccess(results)));
}

if(results.body.errors && results.body.errors.length){
Expand Down

0 comments on commit 52bf0ff

Please sign in to comment.