0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Removing incorrect 405 handling

refs #2757

- As per this convo: https://ghost.slack.com/archives/ghost/p1436895553007431 the 405 handling in Ghost is acting
as a catch all, rather than only returning when the wrong HTTP method is used for a valid resource.
- Implementing proper 405 with express is a challenge, and therefore we defer doing this work until it is needed
This commit is contained in:
Hannah Wolfe 2015-07-14 20:49:19 +01:00
parent 2bdaf773e2
commit b1dd96ecc2
3 changed files with 0 additions and 19 deletions

View file

@ -1,9 +1,5 @@
var errors = require('../errors');
module.exports.methodNotAllowed = function methodNotAllowed(req, res, next) {
next(new errors.MethodNotAllowedError('Unknown method: ' + req.path));
};
module.exports.errorHandler = function errorHandler(err, req, res, next) {
/*jshint unused:false */
var httpErrors = errors.formatHttpErrors(err);

View file

@ -91,8 +91,6 @@ apiRoutes = function apiRoutes(middleware) {
router.post('/uploads', middleware.busboy, api.http(api.uploads.add));
// API Router middleware
router.use(middleware.api.methodNotAllowed);
router.use(middleware.api.errorHandler);
return router;

View file

@ -25,19 +25,6 @@ describe('Middleware: API Error Handlers', function () {
sandbox.restore();
});
describe('methodNotAllowed', function () {
it('calls next with an error', function () {
req.path = 'test';
middleware.api.methodNotAllowed(req, res, next);
next.calledOnce.should.be.true;
next.firstCall.args[0].code.should.equal(405);
next.firstCall.args[0].errorType.should.equal('MethodNotAllowedError');
next.firstCall.args[0].message.should.match(/test$/);
});
});
describe('errorHandler', function () {
it('sends a JSON error response', function () {
errors.logError = sandbox.spy(errors, 'logError');