gpt4 book ai didi

AngularJS 链式 promise 和最终回调

转载 作者:行者123 更新时间:2023-12-03 06:48:00 27 4
gpt4 key购买 nike

所以我有 2 个 promise 函数。当第一个函数出现错误时,我希望它显示错误消息。当完成或失败时,我希望他们执行一个finally catch all 函数,但由于某种原因它不起作用。我的代码如下所示:

// If our garment has a logo
shared.logoExists(garment, model).then(function () {

// Save our panel
return shared.save(model);

// If there was an error
}, function () {

// Display an error message
toastr.warning(localization.resource.logoPlacementError.message);

// Always close the library
}).finally(function () {

// Reset our attachments
self.resetAttachment();

// Hide our library
self.closeLibrary();
});

所以基本上我想要实现的是,如果第一个函数失败,它将显示并出错。当第二个函数失败时,它不会执行任何操作。但无论成功还是失败,它都将始终关闭该库。

有谁知道我怎样才能实现这个目标?

最佳答案

关闭then函数后必须使用.catch:

// If our garment has a logo
shared.logoExists(garment, model).then(function () {

// Save our panel
return shared.save(model);

// If there was an error
}).catch(function () {

// Display an error message
toastr.warning(localization.resource.logoPlacementError.message);

// Always close the library
}).finally(function () {

// Reset our attachments
self.resetAttachment();

// Hide our library
self.closeLibrary();
});

关于AngularJS 链式 promise 和最终回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35798229/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com