From e03fc61fdb0b180bb277a4431108f7458c6af507 Mon Sep 17 00:00:00 2001 From: Andrew Magana Date: Mon, 31 Aug 2020 10:45:30 -0400 Subject: [PATCH] Reverted previous change. Created new function to extract our error from ALKS more appropriately. --- lib/alks-api.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/alks-api.js b/lib/alks-api.js index d02c933..0749e8a 100644 --- a/lib/alks-api.js +++ b/lib/alks-api.js @@ -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('')); @@ -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){