Skip to content

Commit

Permalink
show route method in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
chulkilee committed Oct 5, 2014
1 parent c47828e commit 8d5c1d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
10 changes: 5 additions & 5 deletions lib/route.js
Expand Up @@ -31,9 +31,9 @@ exports = module.exports = internals.Route = function (options, server, env) {

// Setup and validate route configuration

Hoek.assert(options.handler || (options.config && options.config.handler), 'Missing or undefined handler:', options.path);
Hoek.assert(!!options.handler ^ !!(options.config && options.config.handler), 'Handler must only appear once:', options.path); // XOR
Hoek.assert(options.path === '/' || options.path[options.path.length - 1] !== '/' || !server.settings.router.stripTrailingSlash, 'Path cannot end with a trailing slash when server configured to strip:', options.path);
Hoek.assert(options.handler || (options.config && options.config.handler), 'Missing or undefined handler:', options.method, options.path);
Hoek.assert(!!options.handler ^ !!(options.config && options.config.handler), 'Handler must only appear once:', options.method, options.path); // XOR
Hoek.assert(options.path === '/' || options.path[options.path.length - 1] !== '/' || !server.settings.router.stripTrailingSlash, 'Path cannot end with a trailing slash when server configured to strip:', options.method, options.path);

Schema.assert('route', options, options.path);

Expand Down Expand Up @@ -115,7 +115,7 @@ exports = module.exports = internals.Route = function (options, server, env) {
Hoek.assert(!this.settings.validate.payload, 'Cannot validate HEAD or GET requests:', options.path);
}

Hoek.assert(!this.settings.validate.payload || this.settings.payload.parse, 'Route payload must be set to \'parse\' when payload validation enabled:', options.path);
Hoek.assert(!this.settings.validate.payload || this.settings.payload.parse, 'Route payload must be set to \'parse\' when payload validation enabled:', options.method, options.path);
Hoek.assert(!this.settings.jsonp || typeof this.settings.jsonp === 'string', 'Bad route JSONP parameter name:', options.path);

// Authentication configuration
Expand All @@ -124,7 +124,7 @@ exports = module.exports = internals.Route = function (options, server, env) {

// Cache

Hoek.assert(!this.settings.cache || this.method === 'get', 'Only GET routes can use a cache:', options.path);
Hoek.assert(!this.settings.cache || this.method === 'get', 'Only GET routes can use a cache:', options.method, options.path);
this._cache = this.settings.cache ? new Catbox.Policy({ expiresIn: this.settings.cache.expiresIn, expiresAt: this.settings.cache.expiresAt }) : null;

// Handler
Expand Down
7 changes: 3 additions & 4 deletions test/route.js
Expand Up @@ -23,9 +23,8 @@ describe('Route', function () {

var server = new Hapi.Server();
expect(function () {

server.route({ method: 'GET', path: '/', config: {} });
}).to.throw('Missing or undefined handler: /');
}).to.throw('Missing or undefined handler: GET /');
done();
});

Expand All @@ -35,7 +34,7 @@ describe('Route', function () {
expect(function () {

server.route({ method: 'GET', path: '/test/', handler: function () { } });
}).to.throw('Path cannot end with a trailing slash when server configured to strip: /test/');
}).to.throw('Path cannot end with a trailing slash when server configured to strip: GET /test/');
done();
});

Expand Down Expand Up @@ -66,7 +65,7 @@ describe('Route', function () {
expect(function () {

server.route({ method: 'POST', path: '/', handler: function () { }, config: { validate: { payload: {} }, payload: { parse: false } } });
}).to.throw('Route payload must be set to \'parse\' when payload validation enabled: /');
}).to.throw('Route payload must be set to \'parse\' when payload validation enabled: POST /');
done();
});

Expand Down

0 comments on commit 8d5c1d6

Please sign in to comment.