Tag: bugsnag

正确的error handling与NodeJS / Express

我有一个非常基本的迁移代码,看起来像这样。 它删除表格,创build表格,并用一些数据对其进行种子处理。 this.knex.schema.dropTable(this.tableName) .catch((err) => console.log(err)) .then(() => { this.knex.schema.createTable(this.tableName, function(table) { table.increments("id").primary(); table.string("name"); table.integer("parent_id").unsigned().default(0); }) .catch((err) => console.log(err)) .then(() => { this.categories.forEach((category) => { Category.create(category) .catch((err) => console.log(err)) .then((category) => console.log(category.get("name") + " seeded.")) }); }); }); 您可能会注意到,代码上有3x .catch((err) => console.log(err))链。 现在我已经将Bugsnag集成到了我的应用程序中,并且要确保在Bugsnag上正确logging了所有exception/错误,以便我可以修复所有的错误。 不过,现在我所能做的就是将它们login到控制台中。 更糟的是,我重复自己,重复每个catch块的逻辑。 我正在考虑做这样的事情: .catch((err) => ErrorHandler.add(err)) class ErrorHandler { add(err) { // […]

在Restify中res.send()事件之后?

我正在尝试将Bugsnag添加到我的Node Restify服务中。 我们已经有很多的路线,所以我试图不添加Bugsnag调用我们的代码库,我也试图做一些全球性的东西,所以没有错误,开发人员忘记添加错误报告。 从概念上讲,我希望在任何res.send() 之后获得状态码。 如果statusCode> = 400,我想通过调用Bugsnag.notify来通知Bugsnag.notify 。 我已经检查到处都是错误,所以没有任何错误显示给客户端(浏览器,电话等),但是他们确实发送了,例如res.send(401, { message: 'You dont have permission to do that' })我希望能够挂钩和通过谁试图做到这一点,什么路线等问题是我无法得到after火灾: server.on('after', function (req, res, route, error) { console.log('AFTER') }); 我想我误解了after事情。 在定义任何路由或其他中间件( server.use )之前,它位于index.js的顶部。 我的通用代码结构如下所示: server.post('/foo', function (req, res, next) { FooPolicy.create(req, function (err) { if (err) return res.send(err.code, err.data); FooController.create(req.params, function (response) { res.send(response.code, response.data) […]