gpt4 book ai didi

javascript - Node.js 请求中止

转载 作者:行者123 更新时间:2023-12-05 00:27:41 26 4
gpt4 key购买 nike

我正在使用 express 和 body-parser 将大量数据从一台服务器发送到另一台服务器,但一段时间后我收到了这个异常:

{
"message": "request aborted",
"code": "ECONNABORTED",
"expected": 99010,
"length": 99010,
"received": 96872,
"type": "request.aborted"
}

什么可能导致这种情况?如果您需要更多信息,请告诉我。

更新
这是我配置的限制:
application.use(bodyParser.json({ limit: '50mb' }));
application.use(bodyParser.urlencoded({ extended: true, limit: '50mb' }));

最佳答案

这是 body-parser 使用的 raw body 抛出的异常
来自 express 文档:

request abortedThis error will occur when the request is aborted bythe client before reading the body has finished. The received propertywill be set to the number of bytes received before the request wasaborted and the expected property is set to the number of expectedbytes. The status property is set to 400 and type property is set to'request.aborted'.


例如,如果您想处理从正文解析器抛出的所有请求
  'encoding.unsupported',
'entity.parse.failed',
'entity.verify.failed',
'request.aborted',
'request.size.invalid',
'stream.encoding.set',
'parameters.too.many',
'charset.unsupported',
'encoding.unsupported',
'entity.too.large'
使用这个中间件
$ npm i express-body-parser-error-handler
并简单地把它放在你的 body 解析器初始化之后
const bodyParserErrorHandler = require('express-body-parser-error-handler')
...
...

application.use(bodyParser.json({ limit: '50mb' }));
application.use(bodyParser.urlencoded({ extended: true, limit: '50mb' }));
application.use(bodyParserErrorHandler());
...

关于javascript - Node.js 请求中止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55419866/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com