Express JS错误处理

Express JS错误处理,第1张

Express JS错误处理

有关错误处理的示例应用程序/指南可在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");});


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5173053.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-18
下一篇 2022-11-18

发表评论

登录后才能评论

评论列表(0条)

保存