[英]If promise does not return value
I have a promise that returns a function, the function does have its own error handling but sometimes for some reason this gets missed (need to explore this later).我有一个返回函数的承诺,该函数确实有自己的错误处理,但有时由于某种原因会被遗漏(需要稍后探讨)。
I want to add a fallback that if the promise fails/null then return another function.我想添加一个回退,如果承诺失败/为空,则返回另一个函数。
if (completedForm.isValid()) {
return formDataQueue.push(formJson, this.company).then(function () {
return self.trySync();
});
}
Return self.trySync():
needs a error handler to assume it's not there as if it was commented out. Return self.trySync():
需要一个错误处理程序来假设它不存在,就像它被注释掉一样。 My attempt does not seem to work.我的尝试似乎不起作用。
if (completedForm.isValid()) {
return formDataQueue.push(formJson, this.company).then(function () {
//return self.trySync();
}, function(error) {
router.navigate('home');
});
}
Have a look at the difference between .then(…).catch(…)
and .then(…, …)
.看一看的区别.then(…).catch(…)
和.then(…, …)
To handle errors from trySync()
(and only from there), you want to use要处理来自trySync()
(并且仅从那里)的错误,您需要使用
if (completedForm.isValid()) {
return formDataQueue.push(formJson, this.company).then(function () {
return self.trySync().catch(function(error) {
router.navigate('home');
});
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.