使用node-fetch处理http请求,网络出错的时候返回错误:
request to http://xxx/blur/get failed, reason: getaddrinfo ENOTFOUND
at ClientRequest.<anonymous> (file:///Users/project/node_modules/node-fetch/src/index.js:108:11)
at ClientRequest.emit (node:events:513:28)
at Socket.socketErrorListener (node:_http_client:481:9)
at Socket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
type: 'system',
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
erroredSysCall: 'getaddrinfo'
}
然后node进程就退出了。
处理了catch:
fetch(GET_URL)
.then(res => res.json())
.then(json => {
//logic
})
.catch(err => {console.log(err)});
......
process.on('uncaughtException', function(error){
console.log('uncaughtException', error);
});
依然会退出,
我的预期是不要让它退出node进程,如何处理?