有关错误处理的示例应用程序/指南可在https://expressjs.com/en/guide/error-
handling.html上找到,
但是应该可以修复您的代码:
// Require Dependenciesvar express = require('express');var app = express();// Middlewareapp.use(app.router); // you need this line so the .get etc. routes are run and if an error within, then the error is parsed to the next middleware (your error reporter)app.use(function(err, req, res, next) { if(!err) return next(); // you also need this line console.log("error!!!"); res.send("error!!!");});// Routesapp.get('/', function(request, response) { throw "some exception"; response.send('Hello World!');});// Listenapp.listen(5000, function() { console.log("Listening on 5000");});
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)