Fix wrong error message

closes #1466
- added status code for error object
- added test for frontend errors
This commit is contained in:
Sebastian Gierlinger 2013-11-15 15:27:06 +01:00
parent 5c90ef286c
commit fd60a12469
4 changed files with 29 additions and 5 deletions

View File

@ -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);
});
}
};

View File

@ -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);
}

View File

@ -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');
});
});

View File

@ -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('<rss') >= 0, 'Feed should contain <rss');
test.assert(this.getPageContent().indexOf('</rss>') >= 0, 'Feed should contain </rss>');
});
}, true);
});