When a file is missing, I am trying to cancel the promise. However, when I do this I see in the output:
Unhandled rejection Error: ENOENT, open '/home/one/github/infrastructure_manager_ui/gulp/util/token-file.json'
at Error (native)
and also createTokenFile()
does not run as it should. Not sure what I am doing wrong:
function refreshToken() {
var tokenFile = path.join(__dirname, 'token-file.json');
return tokenPromise = fs.readFileAsync(tokenFile, {encoding: 'utf-8'})
.then(JSON.parse)
.cancellable()
.catch(Promise.CancellationError, function(err) {
console.log(err);
if (err.code !== 'ENOENT') {
throw err;
} else {
createTokenFile();
tokenPromise.cancel();
}
});
}