Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#192 Add consistent invocation of the ensureValidToken callback #193

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
10 changes: 8 additions & 2 deletions lib/ocapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function getOptions(host, path, token, method) {
return opts;
}

function ensureValidToken(err, res, success, repeat) {
function ensureValidToken(err, res, callback, repeat) {
// token invalid
if (res && res.body
&& ((res.body.fault && res.body.fault.type == 'InvalidAccessTokenException')
Expand All @@ -70,12 +70,16 @@ function ensureValidToken(err, res, success, repeat) {
// invalid auth header
console.error('Authorization missing or invalid. Please authenticate first by running ' +
'´sfcc-ci auth:login´ or ´sfcc-ci client:auth´.');

callback(err, res);
} else if (res && res.statusCode === 401) {
// authentication failed in WebDAV request
console.error('WebDAV authentication failed. Please (re-)authenticate first by running ' +
'´sfcc-ci auth:login´ or ´sfcc-ci client:auth´. No token auto-renewal is performed. If the problem ' +
'still occurs please check the WebDAV Client Permissions on the instance and ensure your client ID ' +
'has been granted access to required WebDAV resources.');

callback(err, res);
} else if (err && !res) {
// any error, without a proper (JSON) response (body)
// handle special error cases
Expand All @@ -89,9 +93,11 @@ function ensureValidToken(err, res, success, repeat) {
}
console.error('An error occured. Try running the command again with -D,--debug flag.');
console.debug('Error code: %s, message: %s, stack: %s', err.code, err.message, err.stack);

callback(err, res);
} else {
// valid token or different error, trigger callback
success(err, res);
callback(err, res);
}
}

Expand Down