【发布时间】:2018-06-25 23:19:51
【问题描述】:
这是我的 rp 调用:
function hit() = {
return rp(options).then((res) => {
return res;
}).catch((err) => {
console.log("Error occured");
throw err;
})
}
以及调用此函数的函数:
hit().then( res => {
console.log(ae_res)
}).error( err => {
console.err(err) /// code never hits this line
});
当我运行它时,如果 rp 调用成功,则一切正常。但如果它失败了,我永远不会在被调用函数中点击 catch() 块。
我无法传播 rp 调用引发的原始错误。
【问题讨论】:
-
请记住,404 或 500 错误不会构成被拒绝的承诺。联系服务器并获得答复(任何答复)被视为成功请求,即使答复是 4xx 或 5xx 状态。因此,4xx 或 5xx 状态结果仍将进入
then()处理程序。
标签: node.js ecmascript-6 promise request-promise