ember.js的建议错误报告 [英] Recommended error reporting for ember.js

查看:106
本文介绍了ember.js的建议错误报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是ember.js社区关于报告Ember应用程序崩溃的建议?我正在寻找相当于Rails中的exception_notifier gem,以便在用户遇到错误时可以收到通知。



这个堆溢出帖子建议通用的JavaScript错误处理解决方案,包括: p>


  • 处理 window.onerror 自己

  • 使用一个托管服务,可以处理 window.onerror ,例如 Airbrake.io 肌肉



我希望有一些Mixin可以为您提供所有这些错误处理代码,并提供更丰富的错误消息(如发生错误时的当前路由等)。这是否存在?如果没有,人们在做什么来解决这个问题?

解决方案

任何像Rails gem的错误报告将依赖于某些一些服务器后端来处理错误,例如发送管理员等等。有理由的是,Rails将有一个完整的宝石致力于这种事情,因为Rails将要有整个堆栈跟踪,会话和各种各样的对于调试问题而言,对于前端应用程序(例如Ember)来说,方便(必要)的其他变量,所有错误信息都在客户端,所以所有的后端逻辑都会暴露出一个API Ember应用程序可以聊天,将从应用发送到您的任何信息,并将其发送到您的电子邮件,或任何您想要的。



要在Ember中执行此操作,可以指定 Ember.onerror 函数:

  Ember.onerror = function(error){
catch = error;
Em。$。ajax('/ report-error','POST',{
stack:error.stack,
otherInformation:'你要提供的应用程序状态'
});
};

这将收到JavaScript 错误抛出,它可能含有也可能没有包含堆栈跟踪的非标准堆栈,您可以在任何其他应用程序特定状态下发送到服务器发送,虽然你可能想要保持简单,所以你不会导致其他错误,并最终在一个疯狂的错误循环从地狱。


What is the ember.js community recommendation for reporting Ember app crashes? I'm looking for the equivalent of the exception_notifier gem in Rails so that I can be notified if users are experiencing errors.

This Stack Overflow post recommends generic javascript error handling solutions including:

  • Handle window.onerror yourself
  • Use a hosted service that handles window.onerror for you like Airbrake.io or Muscula

I'm hoping there is some kind of Mixin that gives you all this error handling code, and provides richer error messages (such as the current route when the error occurred, etc). Does this exist yet? If not, what are people doing to solve this problem?

解决方案

Any error reporting like the Rails gem is going to depend on some sort of server backend to handle the error, such as emailing admins, etc. It makes sense that Rails would have a whole gem dedicated to this sort of thing, since Rails is going to have the whole stack trace, session, and all sorts of other variables that are convenient(/necessary) to have for debugging the issue, but for front-end apps (e.g. Ember), all the error information is on the client side, so all the backend logic would do is expose an API that your Ember app can talk to which would forward whatever information you send to it from the app and send it to your email, or whatever you want to do with it.

To do this in Ember, you can specify the Ember.onerror function:

Ember.onerror = function(error) {
  caught = error; 
  Em.$.ajax('/report-error', 'POST', {
     stack: error.stack,
     otherInformation: 'whatever app state you want to provide'
  });
};

This receives the JavaScript Error object that was thrown, which may or may not have the non-standard stack property that contains the stack trace which you could send to the server among any other App-specific state you'd want to send, though you'd probably want to keep it simple so that you don't cause other errors and end up in a crazy error loop from hell.

这篇关于ember.js的建议错误报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆