我正在使用 reactjs 开发一个应用程序,它可以让人们发布一些带有主题标签、提及和媒体的帖子。我开始在数据库中保存帖子,经过大量控制后,如果发生错误,我需要从数据库中删除帖子。这里是带有 promises 和 catch 块的函数:
connectDb()
.then( () => { return savePost() } )
.then( () => { return postHashtagRoutine() } )
.then( () => { return iteratePostMedia() } )
.then( () => { return detectLanguage() } )
.then( () => { return updatePost() } )
.then( () => { console.log("pre conn release") } )
.then( () => { conn.release() } )
.then( () => { resolve( { success : "done" } )
.catch( (err) => {
connectDb()
.then( () => { console.log("create post error", err) } )
.then( () => { return removePost() } )
.then( reject(err) )
})
现在的问题是,当我在 postHashtagRoutine() 中调用拒绝时,如果某些主题标签包含停用词,则不会调用 catch 块,并且不会执行控制台日志和 removePost() 函数。
这是我在 postHashtagRoutine() 中调用拒绝的代码部分
Promise.all(promisesCheckStopwords)
.then( () => {
if ( stopwordsId.length > 0){
reject("stopwordsId in post");
}
})