node.js - 如何从nodejs请求捕获像MaxListenersExceededWarning这样的错误?

标签 node.js error-handling request

例如,以下错误不会被请求的常规 try/catch 捕获:

(node:6432) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 pipe listeners added. Use emitter.setMaxListeners() to increase limit
Error: Exceeded maxRedirects. Probably stuck in a redirect loop https://9.20.65.117/
    at Redirect.onResponse (/XXX/node_modules/request/lib/redirect.js:98:27)
    at Request.onRequestResponse (/XXX/node_modules/request/request.js:990:22)
    at emitOne (events.js:115:13)
    at ClientRequest.emit (events.js:210:7)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:565:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:116:23)
    at TLSSocket.socketOnData (_http_client.js:454:20)
    at emitOne (events.js:115:13)
    at TLSSocket.emit (events.js:210:7)
    at addChunk (_stream_readable.js:266:12)

最佳答案

您可以简单地在请求选项对象中禁用遵循 3xx 重定向 请求({followRedirect: false}, ...)

或者将 Nodejs process.setMaxListeners(0); 更改为 0(无限制)

关于node.js - 如何从nodejs请求捕获像MaxListenersExceededWarning这样的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49302921/

相关文章:

python - 使用 Python + Pylons 处理错误

c - C程序中使用链表时出错

javascript - 缺少请求的请求 token

json - Npm 错误代码 EJSONPARSE - 无法解析 json

node.js - Azure 中托管的 Node 服务器上的 Websocket 失败

javascript - 在ReactJS中超过api限制时的错误处理

api - Instagram API : Retrieving the email of currently the logged user

javascript - 使用 node.js 提取所有超链接(来自外部网站)并请求

node.js - 蓝名单应用程序抛出 "Enroll failed to create remote cloudant database for Optional("test1")。超时

node.js - Yeoman Web 应用程序中没有/bower_components/