diff --git a/api/v1/experiment/index.js b/api/v1/experiment/index.js index 1c179db..c1143e9 100644 --- a/api/v1/experiment/index.js +++ b/api/v1/experiment/index.js @@ -19,31 +19,6 @@ module.exports = function(io) { '../../..', '/models/Experiment')).Experiment; - /** - * Answers the request for an undefined action route pair with a Bad Request - * error. - * - * @param res the response object as given by the express router - */ - function respondWithNoSuchRoute(res) { - res.status(400).json({ - 'message': 'No action defined for this method and path' - }); - } - - /* unused routes */ - app.get('/api/v1/experiment', function(req, res) { - return respondWithNoSuchRoute(res); - }); - - app.put('/api/v1/experiment', function(req, res) { - return respondWithNoSuchRoute(res); - }); - - app.delete('/api/v1/experiment', function(req, res) { - return respondWithNoSuchRoute(res); - }); - app.post('/api/v1/experiment/', function(req, res) { var exp = new Experiment({ 'name': req.body.name || haikunate(), @@ -398,5 +373,29 @@ module.exports = function(io) { }); }); + app.get('/api/v1/*', function(req, res) { + return res.status(404).json({ + 'message': 'No such route' + }); + }); + + app.put('/api/v1/*', function(req, res) { + return res.status(404).json({ + 'message': 'No such route' + }); + }); + + app.post('/api/v1/*', function(req, res) { + return res.status(404).json({ + 'message': 'No such route' + }); + }); + + app.delete('/api/v1/*', function(req, res) { + return res.status(404).json({ + 'message': 'No such route' + }); + }); + return app; }; diff --git a/tests/api.js b/tests/api.js index feafd1c..3eea1f6 100644 --- a/tests/api.js +++ b/tests/api.js @@ -169,7 +169,7 @@ it('should return bad request for get /experiment', function(done) { request(app) .get('/api/v1/experiment') - .expect(400) + .expect(404) .send({'name': 'does not matter'}) .end(function(err, doc) { done(err); @@ -179,7 +179,7 @@ it('should return bad request for put /experiment', function(done) { request(app) .put('/api/v1/experiment') - .expect(400) + .expect(404) .send({'name': 'does not matter'}) .end(function(err, doc) { done(err); @@ -189,7 +189,7 @@ it('should return bad request for delete /experiment', function(done) { request(app) .del('/api/v1/experiment') - .expect(400) + .expect(404) .send({'name': 'does not matter'}) .end(function(err, doc) { done(err);