【发布时间】:2015-03-10 04:16:30
【问题描述】:
当文件丢失时,我试图取消承诺。但是,当我这样做时,我会在输出中看到:
Unhandled rejection Error: ENOENT, open '/home/one/github/infrastructure_manager_ui/gulp/util/token-file.json'
at Error (native)
还有createTokenFile() 没有正常运行。不知道我做错了什么:
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();
}
});
}
【问题讨论】:
-
你为什么要取消它自己的处理程序的承诺?!
标签: javascript node.js promise bluebird