[英]How to catch UnhandledPromiseRejectionWarning error only
So I am using request with ES7 async/await. 所以我在ES7 async / await中使用请求。 Getting 404 error is very common there.
出现404错误非常常见。 '
“
try{
status=await rp.delete(baseurl+`/images/${id}`);
.
.
.
}
catch(e){
// catch only UnhandledPromiseRejectionWarning error
}
I want other errors in try block to be thrown as they are. 我想按原样抛出try块中的其他错误。
UnhandledPromiseRejectionWarning
results from unhandled rejections. UnhandledPromiseRejectionWarning
来自未处理的拒绝。 It's not a specific type of errors. 这不是特定类型的错误。 It's a warning in the console that may result in exception in future Node versions.
这是控制台中的警告,可能会在将来的Node版本中导致异常。
Considering that current async
function doesn't handle rejections in parent scope, and this code causes a rejection and UnhandledPromiseRejectionWarning
: 考虑到当前的
async
函数无法处理父级范围内的拒绝,并且此代码会导致拒绝和UnhandledPromiseRejectionWarning
:
status=await rp.delete(baseurl+`/images/${id}`);
e
error in try..catch
will be exactly the error that previously caused UnhandledPromiseRejectionWarning
: e
错误try..catch
将完全先前导致错误UnhandledPromiseRejectionWarning
:
try {
status=await rp.delete(baseurl+`/images/${id}`);
} catch(e){
...
}
I want other errors in try block to be thrown as they are.
我想按原样抛出try块中的其他错误。
If errors are thrown and not caught in parent scope, they will cause UnhandledPromiseRejectionWarning
. 如果引发了错误并且没有将错误捕获到父范围中,则它们将导致
UnhandledPromiseRejectionWarning
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.