简体   繁体   English

如何仅捕获UnhandledPromiseRejectionWarning错误

[英]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.

相关问题 试图捕捉 UnhandledPromiseRejectionWarning: E​​rror: 404 Not Found - Trying to catch UnhandledPromiseRejectionWarning: Error: 404 Not Found 无法捕获UnhandledPromiseRejection警告中的警告 - Cannot catch UnhandledPromiseRejectionWarning in promise 在获取期间捕获 UnhandledPromiseRejectionWarning - Catch UnhandledPromiseRejectionWarning during fetch 尝试Catch无法捕获UnhandledPromiseRejectionWarning - Try Catch unable to catch UnhandledPromiseRejectionWarning UnhandledPromiseRejectionWarning 当从内部捕获重新抛出错误到外部捕获 - UnhandledPromiseRejectionWarning when re-throw error from inner catch to outer catch UnhandledPromiseRejectionWarning:在没有 catch 块的异步 function 中抛出错误,promise 未使用 .catch() 处理 - UnhandledPromiseRejectionWarning: error throwing inside of an async function without a catch block, promise which was not handled with .catch() 如果承诺被拒绝,如何正确地抛出错误? (UnhandledPromiseRejectionWarning) - how to properly throw an error if promise is rejected? (UnhandledPromiseRejectionWarning) Refactoring.catch(handleError) 抛出 UnhandledPromiseRejectionWarning - Refactoring .catch(handleError) throws UnhandledPromiseRejectionWarning 如何修复 UnhandledPromiseRejectionWarning:错误:读取 ETIMEDOUT 和 UnhandledPromiseRejectionWarning:错误:写入 EPROTO 错误 - How do I fix UnhandledPromiseRejectionWarning: Error: read ETIMEDOUT and UnhandledPromiseRejectionWarning: Error: write EPROTO errors UnhandledPromiseRejectionWarning:此错误源自在没有 catch 块的异步函数内部抛出 - UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM