【问题标题】:How can I wrap Meteor.Error method?如何包装 Meteor.Error 方法?
【发布时间】:2019-11-08 17:25:19
【问题描述】:

我想将 Meteor.Error 消息记录到 Winston,但我找不到包装函数 Meteor.Error 的好方法。

这是我在网上找到的代码:

if (Meteor.isServer) {

    logger.info("OVERRIDING METEOR FUNCTION");
    // Override Meteor.Error function to log it
    const errorFunc = Meteor.Error;
    Meteor.Error = function(error, reason, details) {
        console.log("TEST");
        console.log(error);
        console.log(reason);
        console.log(details);
        logger.error('Error: ' + error, {
            error: error,
            reason: reason,
            details: details,
            stack: Error().stack,
            tags: ['error']
        });
        errorFunc.call(this, error, reason, details);
    };
    throw new Meteor.Error("PATATRA", "PTOEOEORORE");
}

Winston 记录错误,但在调用原始 Meteor.Error 后,该方法失败并显示以下消息:

(STDERR) /home/me/.meteor/packages/meteor-tool/.1.6.0_1.15l6i5x.c6ri++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:280
(STDERR)                        throw(ex);
(STDERR)                        ^
(STDERR) [object Object]

我想找到一种方法来正确包装Meteor.error 方法。

【问题讨论】:

    标签: javascript meteor winston


    【解决方案1】:

    我认为只是删除throw new Meteor.Error("PATATRA", "PTOEOEORORE"); 这仍将执行默认的new Meteor.Error() 代码。

    【讨论】:

      猜你喜欢
      • 2020-12-13
      • 1970-01-01
      • 2016-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-24
      相关资源
      最近更新 更多