fixing issue where navigating to a non-existant category_id caused NodeBB

to crash
v1.18.x
Julian Lam 12 years ago
parent 741a5843a1
commit 9e7afcf0ab

@ -11,6 +11,9 @@
<link href="{cssSrc}" rel="stylesheet" media="screen">
<link href="{relative_path}/vendor/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
<link rel="stylesheet" href="{relative_path}/vendor/fontawesome/css/font-awesome.min.css">
<script>
var RELATIVE_PATH = "{relative_path}";
</script>
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript" src="{relative_path}/vendor/jquery/js/jquery-ui-1.10.3.custom.min.js"></script>
<script type="text/javascript" src="{relative_path}/vendor/bootstrap/js/bootstrap.min.js"></script>
@ -19,7 +22,6 @@
<script src="{relative_path}/vendor/requirejs/require.js"></script>
<script src="{relative_path}/vendor/bootbox/bootbox.min.js"></script>
<script>
var RELATIVE_PATH = "{relative_path}";
require.config({
baseUrl: "{relative_path}/src/modules",
waitSeconds: 3

@ -10,12 +10,8 @@ var RDB = require('./redis.js'),
Categories.getCategoryById = function(category_id, current_user, callback) {
Categories.getCategoryData(category_id, function(err, categoryData) {
if(err) {
callback(false);
return;
}
if (err) return callback(err);
var category_name = categoryData.name,
category_slug = categoryData.slug;
@ -75,7 +71,7 @@ var RDB = require('./redis.js'),
categoryData.show_sidebar = 'hidden';
categoryData.no_topics_message = 'show';
callback(categoryData);
callback(null, categoryData);
});
} else {
async.parallel([getTopics, getModerators, getActiveUsers], function(err, results) {
@ -83,7 +79,7 @@ var RDB = require('./redis.js'),
categoryData.moderator_block_class = results[1].length > 0 ? '' : 'none';
categoryData.moderators = results[1];
categoryData.active_users = results[2];
callback(categoryData);
callback(null, categoryData);
});
}
@ -341,7 +337,10 @@ var RDB = require('./redis.js'),
}
Categories.getCategoryData = function(cid, callback) {
RDB.hgetall('category:' + cid, callback);
RDB.exists('category:' + cid, function(err, exists) {
if (exists) RDB.hgetall('category:' + cid, callback);
else callback(new Error('No category found!'));
});
}
Categories.getCategoryFields = function(cid, fields, callback) {

@ -67,7 +67,12 @@
};
Feed.updateCategory = function(cid) {
categories.getCategoryById(cid, 0, function(categoryData) {
categories.getCategoryById(cid, 0, function(err, categoryData) {
if (err) {
console.log('Error: Could not update RSS feed for category ' + cid);
return;
}
var location = '/category/' + categoryData.category_id + '/' + categoryData.category_name,
xml_url = '/category' + cid + '.rss';

@ -209,11 +209,8 @@ var express = require('express'),
}
var category_url = cid + (req.params.slug ? '/' + req.params.slug : '');
categories.getCategoryById(cid, 0, function(returnData) {
if(!returnData) {
res.redirect('404');
return;
}
categories.getCategoryById(cid, 0, function(err, returnData) {
if(err) return res.redirect('404');
res.send(
app.build_header(res) +
@ -379,8 +376,9 @@ var express = require('express'),
});
break;
case 'category' :
categories.getCategoryById(req.params.id, uid, function(data) {
res.json(data);
categories.getCategoryById(req.params.id, uid, function(err, data) {
if (!err) res.json(data);
else res.send(404);
}, req.params.id, uid);
break;
case 'recent' :

Loading…
Cancel
Save