How to use Ember.RSVP.onerror to report exceptions from rejected promises without error handlers
Asked Answered
I

2

7

I just watched this video of a recent panel discussion with the ember-core framework developers.

In the video the panel members are eached asked to share one general debugging tip -- Tom Dale calls out the RSVP onerror handler which makes it possible to globally report exceptions which would have otherwise been swallowed in promises without rejection handlers.

I think this handler will answer a (somewhat confused) question I asked elsewhere on Stack Overflow. Does anyone know how to use this handler or where the docs for it might be?

acceptable promise pattern for 'LOUD' errors?

Illusive answered 1/8, 2013 at 1:49 Comment(0)
C
4

The docs are here: https://github.com/tildeio/rsvp.js#error-handling

This was added around September 2013.

Crude answered 1/8, 2013 at 9:33 Comment(3)
"Usage of RSVP.configure('onerror', yourCustomFunction); is deprecated in favor of using RSVP.on" github.com/tildeio/rsvp.js#error-handlingAbstention
What's the best place to do this?Sneaky
@torazaburo You can do it in an initializer.Abstention
T
3

Hope this helps any other people wanting more with Ember errors and debugging with transpiled Ember code.

First install this: https://github.com/evanw/node-source-map-support

Then -

Template:

{{#if debug}}
  <script src="/browser-source-map-support.js"></script>
  <script>sourceMapSupport.install();</script>
{{/if}}
<script src="/bundle-{{ version }}.js"></script>

Script:

Ember.onerror = function (e) {
  if(debug) {
    console.log(window.sourceMapSupport.getErrorSource(e));
    console.log(e.stack);
  }
  // log error to server
};

Ember.RSVP.configure('onerror', function (e) {
  if(debug) {
    console.log(window.sourceMapSupport.getErrorSource(e));
    console.log(e.stack);
  }
  // log error to server
});

Debugging is easier and faster.

Truant answered 25/7, 2014 at 20:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.