diff --git a/lib/ocapi.js b/lib/ocapi.js index 1a3a51c..47d1a5d 100644 --- a/lib/ocapi.js +++ b/lib/ocapi.js @@ -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') @@ -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 @@ -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); } }