Created
April 3, 2020 22:59
-
-
Save TheSalarKhan/e1712f00a703b7055575180d8e216161 to your computer and use it in GitHub Desktop.
body-parser with custom error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const jsonMiddleware = json({ limit: "10mb", inflate: true }); | |
app.use((req,res,next)=>{ | |
jsonMiddleware(req,res,(err)=>{ | |
if(err){ | |
console.log(err); | |
res.status(400).json({ | |
status: 400, | |
message: "Invalid JSON or request too large" | |
}); | |
} else{ | |
next(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment