我浏览了Express的文档,描述错误处理的部分对我来说完全不透明.
我认为app他们指的是一个实例createServer(),对吧?但我不知道如何在处理请求期间发生异常时阻止node.js炸毁应用程序进程.
我真的不需要任何花哨的东西; 只要有异常,我只想返回500的状态,加上一个空的响应.节点进程不能仅因为某处存在未捕获的异常而终止.
有一个如何实现这个的简单例子吗?
var express = require('express');
var http = require('http');
var app = express.createServer();
app.get('/', function(req, res){
console.log("debug", "calling")
var options = {
host: 'www.google.com',
port: 80,
path: "/"
};
http.get(options, function(response) {
response.on("data", function(chunk) {
console.log("data: " + chunk);
chunk.call(); // no such method; throws here
});
}).on('error', function(e) {
console.log("error connecting" + e.message);
});
});
app.configure(function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.listen(3000);
Run Code Online (Sandbox Code Playgroud)
崩溃整个应用程序,产生追溯 …