简体   繁体   中英

Express Request Aborted

I am using Express.js to implement my backend. I often got the error. I don't know why.

I put the source code to AWS Elastic Beanstalk and set the ELB. If this error triggers more times, it will make all users cannot connect to the server. I always restart the Beanstalk instance to fix this problem. But I don't know when will trigger this error. So please help me to fix it.

Thanks a lot.

{     
    BadRequestError: request aborted
    at IncomingMessage.onAborted (/var/app/current/node_modules/raw-body/index.js:231:10)
    at IncomingMessage.emit (events.js:189:13)
    at IncomingMessage.EventEmitter.emit (domain.js:441:20)
    at abortIncoming (_http_server.js:449:9)
    at socketOnClose (_http_server.js:442:3)
    at Socket.emit (events.js:194:15)
    at Socket.EventEmitter.emit (domain.js:441:20)
    at TCP._handle.close (net.js:600:12)
    message: 'request aborted',
    code: 'ECONNABORTED',
    expected: 18774,
    length: 18774,
    received: 0,
    type: 'request.aborted',
    expose: true,
    statusCode: 400,
    status: 400 
} 
app.use((req, res, next) => {
  logger.info(`marker 1, ${req.header('Content-Type')}, ${req.header('Content-Length')}`)
  next()
})

app.use(express.json({
  type: 'application/json',
  limit: '50mb',
  strict: false,
  verify: (req, res, buf, encoding) => {
    logger.info(`marker 2, ${req.body.length}`)
  }
}));
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));

// catch 404 and forward to error handler
app.use(function(e, req, res, next) {
  // set locals, only providing error in development
  logger.error(e);
  const err = SQError.wrapError(e);
  
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.httpCode || 500);
  var response = req.body.params ? req.body : {};
  logger.error(err, req.app.get('env') === 'development' ? {method: req.body.method || ""} : {});
  if(response.params) 
    response.params.error = err.toJson()
  else 
    response = { error : err.toJson() }
  res.json(response);
});

This error will occur when the request is aborted by the client before reading the body has finished. The status property is set to 400 and type property is set to 'request.aborted'. Please put the setup express code!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM