diff --git a/core/server/controllers/frontend.js b/core/server/controllers/frontend.js index 856571d35c..9e0eca5319 100644 --- a/core/server/controllers/frontend.js +++ b/core/server/controllers/frontend.js @@ -59,7 +59,9 @@ frontendControllers = { res.render('index', {posts: posts, pagination: {page: page.page, prev: page.prev, next: page.next, limit: page.limit, total: page.total, pages: page.pages}}); }); }).otherwise(function (err) { - return next(new Error(err)); + var e = new Error(err.message); + e.status = err.errorCode; + return next(e); }); }, 'single': function (req, res, next) { @@ -78,7 +80,9 @@ frontendControllers = { } }).otherwise(function (err) { - return next(new Error(err)); + var e = new Error(err.message); + e.status = err.errorCode; + return next(e); }); }, 'rss': function (req, res, next) { @@ -151,7 +155,9 @@ frontendControllers = { }); }); }).otherwise(function (err) { - return next(new Error(err)); + var e = new Error(err.message); + e.status = err.errorCode; + return next(e); }); } }; diff --git a/core/server/errorHandling.js b/core/server/errorHandling.js index 21df047f3a..df1c20fb90 100644 --- a/core/server/errorHandling.js +++ b/core/server/errorHandling.js @@ -196,7 +196,7 @@ errors = { if (!err || !(err instanceof Error)) { next(); } - errors.renderErrorPage(500, err, req, res, next); + errors.renderErrorPage(err.status || 500, err, req, res, next); } else { res.send(err.status || 500, err); } diff --git a/core/test/functional/frontend/error_test.js b/core/test/functional/frontend/error_test.js new file mode 100644 index 0000000000..6beac12463 --- /dev/null +++ b/core/test/functional/frontend/error_test.js @@ -0,0 +1,17 @@ +/** + * Tests if RSS exists and is working + */ +/*globals CasperTest, casper */ +CasperTest.begin('Check post not found (404)', 2, function suite(test) { + casper.thenOpen(url + 'asdf/', function (response) { + test.assertEqual(response.status, 404, 'Response status should be 404.'); + test.assertSelectorHasText('.error-code', '404'); + }); +}); + +CasperTest.begin('Check frontend route not found (404)', 2, function suite(test) { + casper.thenOpen(url + 'asdf/asdf/', function (response) { + test.assertEqual(response.status, 404, 'Response status should be 404.'); + test.assertSelectorHasText('.error-code', '404'); + }); +}); \ No newline at end of file diff --git a/core/test/functional/frontend/feed_test.js b/core/test/functional/frontend/feed_test.js index e27e94c112..c524295b26 100644 --- a/core/test/functional/frontend/feed_test.js +++ b/core/test/functional/frontend/feed_test.js @@ -1,10 +1,11 @@ /** * Tests if RSS exists and is working */ +/*globals CasperTest, casper */ CasperTest.begin('Ensure that RSS is available', 3, function suite(test) { casper.thenOpen(url + 'rss/', function (response) { test.assertEqual(response.status, 200, 'Response status should be 200.'); test.assert(this.getPageContent().indexOf('= 0, 'Feed should contain ') >= 0, 'Feed should contain '); }); -}, true); \ No newline at end of file +}); \ No newline at end of file