Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-body-parser-error-handler

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-body-parser-error-handler - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

58

index.js

@@ -1,37 +0,35 @@

function isBodyParserError(error) {
const bodyParserCommonErrorsTypes = [
'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'
]
return bodyParserCommonErrorsTypes.includes(error.type)
function isBodyParserError (error) {
const bodyParserCommonErrorsTypes = [
'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'
]
return bodyParserCommonErrorsTypes.includes(error.type)
}
function bodyParserErrorHandler(
{
// eslint-disable-next-line
function bodyParserErrorHandler (
{
// eslint-disable-next-line
onError = (err, req, res) => {
},
errorMessage = (err) => {
return `Body Parser failed to parse request --> ${err.message}`
}
} = {}) {
return (err, req, res, next) => {
if (err && isBodyParserError(err)) {
onError(err, req, res)
res.status(err.status)
res.send({message: errorMessage(err)})
} else if (err) {
next(err)
} else next()
},
errorMessage = (err) => {
return `Body Parser failed to parse request --> ${err.message}`
}
} = {}) {
return (err, req, res, next) => {
if (err && isBodyParserError(err)) {
onError(err, req, res)
res.status(err.status)
res.send({ message: errorMessage(err) })
} else next(err)
}
}
module.exports = bodyParserErrorHandler
{
"name": "express-body-parser-error-handler",
"version": "1.0.2",
"version": "1.0.3",
"description": "middleware to be set right after body parser in order to return 4xx error back to the client",

@@ -41,7 +41,7 @@ "scripts": {

"describe",
"before",
"beforeAll",
"it",
"after"
"afterAll"
]
}
}

@@ -61,4 +61,4 @@ # express-body-parser-error-handler

// body parser initilization
app.use(urlencoded({extended: false, limit: defaultLimitSize}));
app.use('/', json({limit: '250'}));
app.use(urlencoded({extended: false, limit: '250kb'}));
app.use('/', json({limit: '250kb'}));

@@ -65,0 +65,0 @@ // body parser error handler

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc