Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix beta] Prevent Ember from erroring when the errorThrown property ... #10215

Merged
merged 1 commit into from
Jan 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
});