Node.js request aborted
Asked Answered
T

1

11

I'm using express and body-parser to send large amounts of data from one server to another, but I'm receiving this exception after some time:

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

What could cause this? If you need more information, please let me know.

UPDATE This is my configured limit:

application.use(bodyParser.json({ limit: '50mb' }));
application.use(bodyParser.urlencoded({ extended: true, limit: '50mb' }));
Therese answered 29/3, 2019 at 14:41 Comment(5)
Is it a limit issue?Makedamakefast
Timeout? Due to a too large amount of data? Maybe you should consider streaming, instead of sending everything in one blockHygrostat
Also try executing you apps with the 'DEBUG=body-parser:*' env var, and check the body parser logs for internal warning/errors.Makedamakefast
@Agustin, did you solved this issue?? I fetch the same error.Wernerwernerite
I've found this comment: github.com/expressjs/body-parser/issues/…Rennes
P
5

this is an exception thrown by raw body that is used by body-parser

from express-docs:

request aborted This error will occur when the request is aborted by the client before reading the body has finished. The received property will be set to the number of bytes received before the request was aborted and the expected property is set to the number of expected bytes. The status property is set to 400 and type property is set to 'request.aborted'.

if you want to handle all request thrown from body parser for example

  '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'

use this middleware

$ npm i express-body-parser-error-handler

and simply put it right after your body-parser initialization

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());
...
Plausive answered 25/12, 2021 at 7:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.