diff --git a/tests/parts/route-of-issue-239.js b/tests/parts/route-of-issue-239.js new file mode 100644 index 00000000..252c57bb --- /dev/null +++ b/tests/parts/route-of-issue-239.js @@ -0,0 +1,10 @@ +module.exports = function(express) { + const router = express.Router(); + + router.post("/path", function handler(req, res) { + throw new Error("Whoops"); + //return res.send("test"); + }); + + return router; +} \ No newline at end of file diff --git a/tests/tests/routing/issue-239.js b/tests/tests/routing/issue-239.js new file mode 100644 index 00000000..3f2c904d --- /dev/null +++ b/tests/tests/routing/issue-239.js @@ -0,0 +1,37 @@ +// issue 239 + +const express = require("express"); +const getRouter = require('../../parts/route-of-issue-239'); + +const router = getRouter(express); + +const app = express(); + +app.use(express.json()); + +app.set("catch async errors", true); + +app.use(function jsonErrorHandler(err, req, res, next){ + if(err){ + return res.send("JSON error"); + } + next(); +}) + +app.use("/route", router); + +app.use(function errorHandler(err, req, res, next) { + if(err){ + return res.json(err.toString()); + } + next(); +}); + +app.listen(13333, async() => { + console.log('Server is running on port 13333'); + + const response = await fetch('http://localhost:13333/route/path', { method: 'POST' }); + const body = await response.text(); + console.log(response.status, body); + process.exit(0); +});