The router-specific error handler should be called first on errors within a router prior to hitting the global error-handler. This doesn't happen when an error is handled from within the promisified res.json().
Repro:
import express, {Router} from 'express';
async function bad() {
throw new Error('bad');
}
const router = new Router();
router.get('/:name', (req, res) => {
res.json(bad());
});
// error handler on this router is never called
router.use((err, req, res, next) => {
res.status(400);
});
const app = express();
app.use('/', router);
The router-specific error handler should be called first on errors within a router prior to hitting the global error-handler. This doesn't happen when an error is handled from within the promisified
res.json()
.Repro: