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
(bodyParser, req, res) => new Promise((resolve, reject) => { try { bodyParser(req, res, err => { if (err instanceof Error) { reject(err); } else { resolve(); } }); } catch (e) { reject(e); } })
Bullet-proof. Future-aware. WTFPL-Licensed. And also useful w/ async/await.