Node.js based forum software built for the modern web
fix crash when you go to /topics/nonexistant
Baris Usakli34432773d664
diff --git a/public/src/templates.js b/public/src/templates.jsindex 3c0f40531d..c2b75a4779 100644--- a/public/src/templates.js+++ b/public/src/templates.js@@ -40,6 +40,7 @@ var templates = {};for (var t in templatesToLoad) {(function(file) {$.get('/templates/' + file + '.tpl?v=' + timestamp, function(html) {+var template = function() {this.toString = function() {return this.html;@@ -168,6 +169,12 @@ function load_template(callback, url, template) {jQuery.get(API_URL + url, function(data) {+ console.log(data);+ if(!data) {+ window.location.href = '/403';+ return;+ }+var tpl = templates.get_custom_map(url);if (tpl == false && !templates[url]) {diff --git a/src/posts.js b/src/posts.jsindex 42a98c83e8..9b56403f68 100644--- a/src/posts.js+++ b/src/posts.js@@ -12,6 +12,7 @@ marked.setOptions({(function(Posts) {Posts.get = function(callback, tid, current_user, start, end) {+if (start == null) start = 0;if (end == null) end = start + 10;@@ -74,6 +75,11 @@ marked.setOptions({// get all data for thread in asynchronous fashionRDB.lrange('tid:' + tid + ':posts', start, end, function(err, pids) {RDB.handle(err);++ if(pids.length === 0){+ callback(false);+ return;+ }var content = [], uid = [], timestamp = [], pid = [], post_rep = [], editor = [], editTime = [], deleted = [];diff --git a/src/topics.js b/src/topics.jsindex ead41792d1..0e2efd92d5 100644--- a/src/topics.js+++ b/src/topics.js@@ -20,6 +20,12 @@ var RDB = require('./redis.js'),var range_var = (category_id) ? 'categories:' + category_id + ':tid' : 'topics:tid';RDB.smembers(range_var, function(err, tids) {++ if(tids.length === 0) {+ callback(false);+ return;+ }+var title = [],uid = [],timestamp = [],diff --git a/src/webserver.js b/src/webserver.jsindex 3de6acdc98..4202bfb575 100644--- a/src/webserver.js+++ b/src/webserver.js@@ -154,26 +154,46 @@ var express = require('express'),break;case 'topic' :posts.get(function(data) {+ if(!data) {+ res.send(false);+ return;+ }res.send(JSON.stringify(data));}, req.params.id, (req.user) ? req.user.uid : 0);break;case 'category' :topics.get(function(data) {+ if(!data) {+ res.send(false);+ return;+ }res.send(JSON.stringify(data));}, req.params.id, (req.user) ? req.user.uid : 0);break;case 'latest' :topics.get(function(data) {+ if(!data) {+ res.send(false);+ return;+ }res.send(JSON.stringify(data));});break;case 'popular' :topics.get(function(data) {+ if(!data) {+ res.send(false);+ return;+ }res.send(JSON.stringify(data));});break;case 'active' :topics.get(function(data) {+ if(!data) {+ res.send(false);+ return;+ }res.send(JSON.stringify(data));});break;