diff --git a/lib/http/base.js b/lib/http/base.js index 65cf10606..dad41da79 100644 --- a/lib/http/base.js +++ b/lib/http/base.js @@ -36,13 +36,16 @@ HttpClient.prototype.request = function (options) { let requestPromise; const requestOptions = prepareRequestOptions.call(this, options); + const requestController = new AbortController(); + let sendRequest = async function sendRequest() { Logger.getInstance().trace('Request%s - sending.', requestUtil.describeRequestFromOptions(requestOptions)); const timer = new ExecutionTimer().start(); - requestPromise = axios.request(requestOptions).then(response => { + requestPromise = axios.request(requestOptions, { signal: requestController }).then(response => { const httpResponseTime = timer.getDuration(); Logger.getInstance().debug('Request%s - response received after %s milliseconds with status %s.', requestUtil.describeRequestFromOptions(requestOptions), httpResponseTime, response.status); sanitizeAxiosResponse(response); + parseResponseData(response); if (Util.isFunction(options.callback)) { Logger.getInstance().trace('Request%s - calling callback function.', requestUtil.describeRequestFromOptions(requestOptions)); return options.callback(null, normalizeResponse(response), response.data); @@ -78,12 +81,13 @@ HttpClient.prototype.request = function (options) { // methods we're comfortable exposing to the outside world return { abort: function () { - if (requestPromise) { + if (requestController) { Logger.getInstance().trace('Request%s - aborting.', requestUtil.describeRequestFromOptions(requestOptions)); - // TODO: This line won't work - promise has no method called abort - requestPromise.abort(); + requestController.abort(); + Logger.getInstance().debug('Request%s - aborted.', requestUtil.describeRequestFromOptions(requestOptions)); } - } + }, + requestPromise: requestPromise }; }; @@ -106,7 +110,7 @@ HttpClient.prototype.requestAsync = async function (options) { Logger.getInstance().debug('Request%s - response received after %s milliseconds with status %s.', requestUtil.describeRequestFromOptions(requestOptions), httpResponseTime, response.status); parseResponseData(response); sanitizeAxiosResponse(response); - return response; + return normalizeResponse(response); } catch (err) { const httpResponseTime = timer.getDuration(); Logger.getInstance().debug('Request%s - failed after %s milliseconds. Error will be re-raised.', requestUtil.describeRequestFromOptions(options), httpResponseTime); diff --git a/lib/services/sf.js b/lib/services/sf.js index 4a1ce42a9..4c8a5683b 100644 --- a/lib/services/sf.js +++ b/lib/services/sf.js @@ -653,7 +653,7 @@ function StateAbstract(options) { if (body.code === GSErrors.code.ID_TOKEN_INVALID && data.authnMethod === 'TOKEN') { Logger.getInstance().debug('ID Token being used has expired. Reauthenticating'); - const key = Util.buildCredentialCacheKey(connectionConfig.host, + const key = Util.buildCredentialCacheKey(connectionConfig.host, connectionConfig.username, AuthenticationTypes.ID_TOKEN_AUTHENTICATOR); await GlobalConfig.getCredentialManager().remove(key); await auth.reauthenticate(requestOptions.json);