Skip to content

Commit

Permalink
Merge pull request #10215 from bmac/assign-to-string-error
Browse files Browse the repository at this point in the history
[Bugfix beta] Prevent Ember from erroring when the errorThrown property ...
  • Loading branch information
stefanpenner committed Jan 14, 2015
2 parents 5975723 + 0cd800b commit c0f38aa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/ember-runtime/lib/ext/rsvp.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ RSVP.onerrorDefault = function (e) {
if (e && e.errorThrown) {
// jqXHR provides this
error = e.errorThrown;
if (typeof error === 'string') {
error = new Error(error);
}
error.__reason_with_error_thrown__ = e;
} else {
error = e;
Expand Down
27 changes: 27 additions & 0 deletions packages/ember-runtime/tests/ext/rsvp_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,30 @@ test('rejections like jqXHR which have errorThrown property work', function() {
Ember.testing = wasEmberTesting;
}
});


test('rejections where the errorThrown is a string should wrap the sting in an error object', function() {
expect(2);

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

try {
Ember.testing = false;
Ember.onerror = function(error) {
console.log('error', error);
equal(error.message, 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 = "OMG what really happened";
var jqXHR = {
errorThrown: actualError
};

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

0 comments on commit c0f38aa

Please sign in to comment.