Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TheSalarKhan/e1712f00a703b7055575180d8e216161 to your computer and use it in GitHub Desktop.
Save TheSalarKhan/e1712f00a703b7055575180d8e216161 to your computer and use it in GitHub Desktop.
body-parser with custom error
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