Skip to content

Commit

Permalink
[Bugfix beta] RSVP.onerrordefault now unwraps reason like jqXHR to be…
Browse files Browse the repository at this point in the history
… its errorThrown.

This should provide much more actionable errors.
  • Loading branch information
stefanpenner committed Nov 13, 2014
1 parent 54c51f2 commit bf5e73a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/ember-runtime/lib/ext/rsvp.js
Expand Up @@ -41,7 +41,17 @@ RSVP.Promise.prototype.fail = function(callback, label){
return this['catch'](callback, label);
};

RSVP.onerrorDefault = function (error) {
RSVP.onerrorDefault = function (e) {
var error;

if (e && e.errorThrown) {
// jqXHR provides this
error = e.errorThrown;
error.__reason_with_error_thrown__ = e;
} else {
error = e;
}

if (error && error.name !== 'TransitionAborted') {
if (Ember.testing) {
// ES6TODO: remove when possible
Expand Down
25 changes: 25 additions & 0 deletions packages/ember-runtime/tests/ext/rsvp_test.js
Expand Up @@ -117,3 +117,28 @@ test('TransitionAborted errors are not re-thrown', function() {

ok(true, 'did not throw an error when dealing with TransitionAborted');
});

test('rejections like jqXHR which have errorThrown property work', function() {
expect(2);

var wasEmberTesting = Ember.testing;
var wasOnError = Ember.onerror;

try {
Ember.testing = false;
Ember.onerror = function(error) {
equal(error, actualError, 'expected the real error on the jqXHR');
equal(error.__reason_with_error_thrown__, jqXHR, 'also retains a helpful reference to the rejection reason');
};

var actualError = new Error("OMG what really happend");
var jqXHR = {
errorThrown: actualError
};

run(RSVP, 'reject', jqXHR);
} finally {
Ember.onerror = wasOnError;
Ember.testing = wasEmberTesting ;
}
});

0 comments on commit bf5e73a

Please sign in to comment.