Tag: error handling

Node.js – 比process.on('uncaughtException',fn)更好的error handling?

在我的应用程序的顶部,我有这样的代码: process.on('uncaughtException', function(err) { console.log("We found an uncaught exception."); console.log(err); }); 如果我search我的日志grep -i -A10 -B3 'uncaught exception' logfile ,我可以得到一些体面的信息。 但是我不知道exception抛出的执行上下文是什么,错误是什么等等。 我应该使用什么样的模式?

我如何在node.js中运行这个脚本?

我已经安装了所有需要使用CMD运行这个脚本的模块。 当我通过webmatrix在node.js中运行这个脚本时: var http = require('http'); var everyauth = require('everyauth'); var app = require('express').createServer(); app.get('/', function(request, response) { response.send('Hello Express!!'); }); app.listen(2455); 这不起作用。 错误是: iisnode encountered an error when processing the request. HRESULT: 0x2 HTTP status: 500 HTTP reason: Internal Server Error You are receiving this HTTP 200 response because system.webServer/iisnode/@devErrorsEnabled configuration setting is 'true'. […]

在expressjsasynchronous瀑布处理错误

我不明白为什么expressjs在抛出async.waterfall时不处理错误 var express = require('express') , app = express.createServer() , async = require('async'); app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); app.get('/error', function(req, res){ throw Error('Aie'); }); app.get('/asyncerror', function(req, res){ var that = this; async.waterfall([ function(next){ console.log('1'); next("42", "2"); }, function(arg, next) { console.log(arg); res.json('ok'); } ], function(err){ console.log(this); throw Error('Aie'); }); }); app.listen(8888, function(){ console.log('Listen on […]

早午餐设置LOGGY_STACKS = true

我正在开发一个早午餐的应用程序。 我是新来的,并跟踪错误,我必须启用LOGGY_STACKS = true。 我怎样才能设置它? Stack trace was suppressed. Run with `LOGGY_STACKS=true` to see the trace.

在Express和Restify中处理uncaughtException

我使用restify和express。 在restify,我这样创build服务器: server = restify.createServer(serverSettings); 然后,我可以像这样处理uncaughtException: server.on('uncaughtException', function(req, res, route, err) {}) 这与process.on('uncaughtException')不同。 因为它捕获了所有的uncaughtException并且可以给客户端一个响应。 所以我喜欢这种方式来捕捉exception。 但在Express中,我找不到像这样的东西。 所以想问一下,有没有同样的事情呢? 或者有一些方法可以实现相同的function?

为什么express的默认error handling程序行为将堆栈跟踪返回给客户端?

我试图让我的http api服务器中的error handling工作正常,我不明白节点的error handling行为。 我已经定义了我自己的错误对象,如下所示: function ServerError(statusCode, err, message) { this.status = statusCode; if (err != undefined) { this.err = err; if (message != undefined) { this.message = message; } else { this.message = err.message || err; } } } ServerError.prototype = new Error(); 我使用这样的对象,无论是在中间件或处理程序: function forceError() { return function(req, res, next) { next(new ServerError(500, […]

在Node.js + Express中使用承诺处理错误

使用Node.js + Express(4)+ Mongoose(使用promises而不是callback),我不能理清如何清理error handling。 我所得到的(而非简化的)是: app.get('/xxx/:id', function(request, response) { Xxx.findById(request.params.id).exec() .then(function(xxx) { if (xxx == null) throw Error('Xxx '+request.params.id+' not found'); response.send('Found xxx '+request.params.id); }) .then(null, function(error) { // promise rejected switch (error.name) { case 'Error': response.status(404).send(error.message); // xxx not found break; case 'CastError': response.status(404).send('Invalid id '+request.params.id); break; default: response.status(500).send(error.message); break; } }); }); […]

为什么这个基本的Node.jserror handling不起作用?

Node.js的: var https = require("https"); var request = https.get("google.com/", function(response) { console.log(response.statusCode); }); request.on("error", function(error) { console.log(error.message); }); 如果我添加https://到谷歌域名,那么我得到了预期的状态代码200。 现在,我希望能够捕获错误,并将类似于“连接ECONNREFUSED”的错误消息打印到terminal控制台。 相反,它将堆栈跟踪打印到terminal。

错误:无法find模块'扳手',我得到这个错误,当我运行gulp命令

我在本地和全球都安装了npm,bower和gulp。但是当我在该文件夹中运行gulp时,出现了这个错误。 Error: Cannot find module 'wrench' at Function.Module._resolveFilename (module.js:325:15) at Function.Module._load (module.js:276:25) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object.<anonymous> (/home/myPC/documents/workspace/frontend/gulpfile.js:10:14) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) 这是我的gulpfile.js 'use strict'; var gulp = require('gulp'); var wrench = require('wrench'); wrench.readdirSyncRecursive('./gulp').filter(function (file) { return (/\.(js|coffee)$/i).test(file); […]

Node.jserror handling – 如何处理未定义的值导致错误

以此URL为例: https : //api.eveonline.com/eve/CharacterID.xml.aspx?names=Khan 使用xml2js node.js模块,你可以parsingXML,虽然看起来不太漂亮: var CharacterID = response.eveapi.result[0].rowset[0].row[0].$.characterID; 该应用程序在运行2周后崩溃,全部因为rowset [0]未定义。 在此之前,它因为eveapi没有被定义而崩溃。 真的,我的if-else是否必须像这样才能防止服务器崩溃,由于愚蠢的未定义的对象错误? if (!response.eveapi || !response.eveapi.result[0] || !response.eveapi.result[0].rowset[0] || !response.eveapi.result[0].rowset[0].row[0]) { return res.send(500, "Error"); 除了明显的if (err) return res.send(500, "Error"); error handling在适用的情况下, 未定义错误的一般做法是什么?