Skip to content

Commit

Permalink
Add requested path to router error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
kuuttia committed Apr 13, 2017
1 parent 4eeb805 commit 9434214
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions route/router/Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Route.prototype.public = function () {

/**
* This handler sends response by itself and we shouldn't apply default response sending actions for this one.
*
*
* Handler must return promise, which doesn't resolve until res.send is called.
*
* @returns {Route}
Expand Down Expand Up @@ -148,7 +148,8 @@ Route.prototype.handlerMiddleware_ = function (req, res, next) {
return promise.then(function (result) {
if (result === NO_RESULT) {
if (!res.headersSent) {
throw new Error("Handler function did not return promise which won't resolve until response has been sent.");
throw new Error("Handler function did not return promise which won't resolve until response has been sent. " +
"Requested path: " + req.path);
}
return;
}
Expand All @@ -158,7 +159,8 @@ Route.prototype.handlerMiddleware_ = function (req, res, next) {
sendResult(result, req, res);
}
if (!res.headersSent) {
throw new Error("Unexpected error, response was not sent by any handler for some reason. This should not be possible.");
throw new Error("Unexpected error, response was not sent by any handler for some reason. " +
"Requested path: " + req.path);
}
}).catch(next);
};
Expand All @@ -182,7 +184,7 @@ Route.prototype.handle_ = function (req, res, next) {
if (this.defaultAuthHandler) {
authHandlers.unshift(this.defaultAuthHandler);
} else {
throw new Error("No defaultAuthHandler set for non-public route.");
throw new Error("No defaultAuthHandler set for non-public route. Requested path: " + req.path);
}
}

Expand All @@ -197,7 +199,7 @@ Route.prototype.handle_ = function (req, res, next) {
} else if (ret instanceof Error) {
throw ret;
} else {
throw new Error("Invalid return value from auth handler.");
throw new Error("Invalid return value from auth handler. Requested path: " + req.path);
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion route/tests/Router.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ describe('Router', function () {

var nextSpy = spy(function (err) {
expect(err instanceof Error).to.equal(true);
expect(err.message).to.equal("No defaultAuthHandler set for non-public route.");
expect(err.message).to.contain("No defaultAuthHandler set for non-public route.");
// Should not have called response.end or response.send or the handler.
expect(endSpy.calls).to.have.length(0);
expect(sendSpy.calls).to.have.length(0);
Expand Down

0 comments on commit 9434214

Please sign in to comment.