Skip to content

Commit

Permalink
[BUGFIX beta] Ensure wrapped errors are logged properly.
Browse files Browse the repository at this point in the history
ember-data and ic-ajax tag rejections with jqxhr’s with the original error when possible. This error is appended as jqxhr.errorThrown. Logging this error, dramatically improves debugability of request related transition failures
  • Loading branch information
stefanpenner authored and rwjblue committed Feb 16, 2015
1 parent 3ac2fdb commit cd9c472
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 cd9c472

Please sign in to comment.