处理post-parse error SocketOnEnd未捕获的异常
发布于 7 年前 作者 electrmc 3171 次浏览 来自 问答

今天在处理post请求时,会出现如下的错误: IMG_0689.JPG 查到出现这个错误原因是客户端关闭了socket。但是我想如何才能捕获到这个错误,而不是仅在vscode中打印。 我用如下两种方案都没捕获到该问题: 方案1,监听request的aborted事件没有捕获到:

ctx.req.on('aborted',function(err){
          console.log(err);
        });

方案2:

process.on('uncaughtException', function(err) {
    console.error('Error caught in uncaughtException event:', err);
});

问题:应该怎么捕获和处理未处理的异常?通常情况下nodejs如何处理此类异常?常用的第三方插件是什么?

回到顶部