8

I've rewritten a web application using angular. But now i have the problem that it's not as easy as window.onerror = function(...) { ... } to send clientside errors to the server. But this is really helpful to detect errors.

I added a custom exception handler to angular using the following code

    $provide.decorator("$exceptionHandler", function($delegate) {
    return function(exception, cause) {
        $delegate(exception, cause);
        log2server(exception + " (" + cause + ")");
    };
});

But this wont allow me to get the location where the exception came from. Any hints/experience how to tackle this? I would also love a solution which is able to work with http://stacktracejs.com/

4

3 回答 3

10

我目前正在使用TraceKit,它似乎工作得很好。

只需将其添加到您的角度启动代码中

$provide.decorator("$exceptionHandler", function($delegate) {
    return function(exception, cause) {
        TraceKit.report(exception);
        $delegate(exception, cause);
    };
});

+这个地方

TraceKit.report.subscribe(function(errorReport) {
    var msg = 'msg: ' + errorReport.message + '\n\n';
    msg +="::::STACKTRACE::::\n"
    for(var i = 0; i < errorReport.stack.length; i++) {
        msg += "stack[" + i + "] " + errorReport.stack[i].url + ":" + errorReport.stack[i].line + "\n";
    }
    // log to server
    ...
}
于 2014-01-10T00:53:52.743 回答
5

我们可以使用Eric Wendelin 的 stacktrace.js

  1. AngularJS具有良好的错误处理能力。
  2. stacktrace.js试图解决在所有浏览器中获取正确错误信息的重要问题。

所以我们可以围绕 stacktrace.js 创建一个角度包装器,它提供了全面的错误处理。

以下是 2 篇博客文章,它们很好地解释了如何使用AngularJS和将客户端 JS 错误记录到服务器端stacktrace.js

  1. http://engineering.talis.com/articles/client-side-error-logging/
  2. http://www.bennadel.com/blog/2542-logging-client-side-errors-with-angularjs-and-stacktrace-js.htm
于 2015-02-18T06:01:44.560 回答
0

免责声明:我是基于 django 的应用程序开发人员。

我可以建议您使用基于raven的解决方案。它是具有许多绑定(也是javascript )的日志聚合服务,以及基于 django 的出色监控应用程序哨兵。

于 2013-10-13T22:50:54.170 回答