流星服务器捕获未处理的错误



我目前正在使用 window.onerror 函数在客户端上记录未经处理的异常,如下所示:

window.onerror = function (msg) { //This function logs uncaught errors from the client
    logIt({category:"Client Error",message:msg});
    return false;
};

有没有办法在服务器端做同样的事情?我希望能够在控制台输出中出现某些内容时调用函数。

我试过Meteor.onerrorMeteor.onErrorwindows.onError

编辑:我仍然没有找到一种方法来做到这一点,但我今天早上肯定遇到了需求。任何帮助,不胜感激。

正在阅读一些我可以使用process.on('uncaughtException')的地方,但我也在阅读其他我不能的地方。它似乎对我不起作用。

我想

我想通了,尽管这不是我希望的解决方案。

在此文件的帮助下...

if (Meteor.isServer) {
  var consoleLogOrig = console.log;
  console.log = function(arguments) {
    var msg;
    if (typeof arguments === "string") {
      msg = arguments
    } else {
      msg = arguments[0]
    }
    logIt({
      type: "Server Console",
      message: msg,
      attachment: arguments
    });
    consoleLogOrig.call(console, arguments);
  };
}

相关内容

最新更新