I want to catch the error from the bodyParser() middleware when I send a json object and it is invalid because I want to send a custom response instead of a generic 400 erro
I think your best bet is to check for SyntaxError:
SyntaxError
app.use(function (error, req, res, next) { if (error instanceof SyntaxError) { sendError(res, myCustomErrorMessage); } else { next(); } });