我对nodejs比较新,所以我将更详细地解释一下我想做什么.
我有一个网络服务器.如果请求失败,我想记录该异常的堆栈跟踪,但是提供错误页面而不是使服务器崩溃.
例如,处理请求的函数:
var Q = require('q');
var requestHandler = function () {
// Here I get the data etc. that was requested. As this is not important, just a dummy here
Q.resolve()
// Now I answer the request
.then(function (data) {
// Dummy Code representing the sending of a response
console.log('sending response …');
console.log('oh no! an exception');
// Now an Exception occurs
throw new Error('You did something wrong!');
})
// If there was any error, show the error page …Run Code Online (Sandbox Code Playgroud) 在我的文章集合中,我有一个文本索引:
{
"v" : 1,
"key" : {
"_fts" : "text",
"_ftsx" : 1
},
"name" : "title_text_abstract_text_body_text",
"ns" : "foo.articles",
"weights" : {
"abstract" : 1,
"body" : 1,
"title" : 1
},
"default_language" : "english",
"language_override" : "language",
"textIndexVersion" : 2
}
Run Code Online (Sandbox Code Playgroud)
在我的文章集中,我有一个这样的条目:
{
"_id" : ObjectId("5477c28c807a9cd660ccd567"),
"title" : "Hallo Welt!",
"author" : "foo",
"publishDate" : ISODate("2014-11-28T17:00:00Z"),
"language" : "de",
"abstract" : "Mein erster Artikel!",
"body" : "Dieser Artikel ist in deutscher Sprache.",
"__v" : 0
}
Run Code Online (Sandbox Code Playgroud)
(有在实际上不同的价值观 …