diff --git a/src/categories/index.js b/src/categories/index.js index f7a7a7e8b0..35fd8f740f 100644 --- a/src/categories/index.js +++ b/src/categories/index.js @@ -34,7 +34,7 @@ Categories.getCategoryById = function (data, callback) { }, function (categories, next) { if (!categories[0]) { - return next(new Error('[[error:invalid-cid]]')); + return callback(null, null); } category = categories[0]; data.category = category; diff --git a/src/controllers/category.js b/src/controllers/category.js index bc59b9d8a3..5490b5c2ea 100644 --- a/src/controllers/category.js +++ b/src/controllers/category.js @@ -103,6 +103,9 @@ categoryController.get = function (req, res, callback) { }, next); }, function (categoryData, next) { + if (!categoryData) { + return callback(); + } categories.modifyTopicsByPrivilege(categoryData.topics, userPrivileges); if (categoryData.link) { diff --git a/src/routes/feeds.js b/src/routes/feeds.js index 8917b623dd..569db57266 100644 --- a/src/routes/feeds.js +++ b/src/routes/feeds.js @@ -148,14 +148,14 @@ function generateForTopic(req, res, callback) { ], callback); } -function generateForCategory(req, res, next) { +function generateForCategory(req, res, callback) { if (meta.config['feeds:disableRSS']) { return controllers404.send404(req, res); } var cid = req.params.category_id; var category; if (!parseInt(cid, 10)) { - return next(); + return setImmediate(callback); } async.waterfall([ function (next) { @@ -177,6 +177,9 @@ function generateForCategory(req, res, next) { }, function (results, next) { category = results.category; + if (!category) { + return callback(); + } validateTokenIfRequiresLogin(!results.privileges.read, cid, req, res, next); }, function (next) { @@ -191,7 +194,7 @@ function generateForCategory(req, res, next) { function (feed) { sendFeed(feed, res); }, - ], next); + ], callback); } function generateForTopics(req, res, next) { diff --git a/test/categories.js b/test/categories.js index 8de352055b..af11a3528b 100644 --- a/test/categories.js +++ b/test/categories.js @@ -57,7 +57,7 @@ describe('Categories', function () { stop: -1, uid: 0, }, function (err, categoryData) { - assert.equal(err, null); + assert.ifError(err); assert(categoryData); assert.equal('Test Category & NodeBB', categoryData.name); @@ -67,6 +67,17 @@ describe('Categories', function () { }); }); + it('should return null if category does not exist', function (done) { + Categories.getCategoryById({ + cid: 123123123, + start: 0, + stop: -1, + }, function (err, categoryData) { + assert.ifError(err); + assert.strictEqual(categoryData, null); + done(); + }); + }); it('should load a category route', function (done) { request(nconf.get('url') + '/api/category/' + categoryObj.cid + '/test-category', { json: true }, function (err, response, body) {