Skip to content

Commit

Permalink
Merge pull request #10475 from stefanpenner/log-error-error-thrown
Browse files Browse the repository at this point in the history
[BUGFIX beta] Ensure wrapped errors are logged properly.
  • Loading branch information
rwjblue committed Feb 16, 2015
2 parents 3ac2fdb + cd9c472 commit f587341
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/ember-routing/lib/system/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,14 @@ var defaultActionHandlers = {
}
};

function logError(error, initialMessage) {
function logError(_error, initialMessage) {
var errorArgs = [];
var error;
if (_error && typeof _error === 'object' && typeof _error.errorThrown === 'object') {
error = _error.errorThrown;
} else {
error = _error;
}

if (initialMessage) { errorArgs.push(initialMessage); }

Expand Down
25 changes: 25 additions & 0 deletions packages/ember/tests/routing/basic_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3196,6 +3196,31 @@ QUnit.test("rejecting the model hooks promise with a non-error prints the `messa
bootApplication();
});

QUnit.test("rejecting the model hooks promise with an error with `errorThrown` property prints `errorThrown.message` property", function() {
var rejectedMessage = 'OMG!! SOOOOOO BAD!!!!';
var rejectedStack = 'Yeah, buddy: stack gets printed too.';

Router.map(function() {
this.route("yippie", { path: "/" });
});

Ember.Logger.error = function(initialMessage, errorMessage, errorStack) {
equal(initialMessage, 'Error while processing route: yippie', 'a message with the current route name is printed');
equal(errorMessage, rejectedMessage, "the rejected reason's message property is logged");
equal(errorStack, rejectedStack, "the rejected reason's stack property is logged");
};

App.YippieRoute = Ember.Route.extend({
model: function() {
return Ember.RSVP.reject({
errorThrown: { message: rejectedMessage, stack: rejectedStack }
});
}
});

bootApplication();
});

QUnit.test("rejecting the model hooks promise with no reason still logs error", function() {
Router.map(function() {
this.route("wowzers", { path: "/" });
Expand Down

0 comments on commit f587341

Please sign in to comment.