0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Error handling for the frontend routes

This commit is contained in:
Hannah Wolfe 2013-09-17 01:54:36 +01:00
parent de7143bc62
commit 79f75865a1

View file

@ -8,12 +8,14 @@ var Ghost = require('../../ghost'),
api = require('../api'), api = require('../api'),
RSS = require('rss'), RSS = require('rss'),
_ = require('underscore'), _ = require('underscore'),
errors = require('../errorHandling'),
when = require('when'),
ghost = new Ghost(), ghost = new Ghost(),
frontendControllers; frontendControllers;
frontendControllers = { frontendControllers = {
'homepage': function (req, res) { 'homepage': function (req, res, next) {
// Parse the page number // Parse the page number
var pageParam = req.params.page !== undefined ? parseInt(req.params.page, 10) : 1, var pageParam = req.params.page !== undefined ? parseInt(req.params.page, 10) : 1,
postsPerPage = parseInt(ghost.settings('postsPerPage'), 10), postsPerPage = parseInt(ghost.settings('postsPerPage'), 10),
@ -55,16 +57,25 @@ frontendControllers = {
ghost.doFilter('prePostsRender', page.posts, function (posts) { ghost.doFilter('prePostsRender', page.posts, function (posts) {
res.render('index', {posts: posts, pagination: {page: page.page, prev: page.prev, next: page.next, limit: page.limit, total: page.total, pages: page.pages}}); 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));
}); });
}, },
'single': function (req, res) { 'single': function (req, res, next) {
api.posts.read({'slug': req.params.slug}).then(function (post) { api.posts.read({'slug': req.params.slug}).then(function (post) {
if (post) {
ghost.doFilter('prePostsRender', post.toJSON(), function (post) { ghost.doFilter('prePostsRender', post.toJSON(), function (post) {
res.render('post', {post: post}); res.render('post', {post: post});
}); });
} else {
next();
}
}).otherwise(function (err) {
return next(new Error(err));
}); });
}, },
'rss': function (req, res) { 'rss': function (req, res, next) {
// Initialize RSS // Initialize RSS
var siteUrl = ghost.config().url, var siteUrl = ghost.config().url,
pageParam = req.params.page !== undefined ? parseInt(req.params.page, 10) : 1, pageParam = req.params.page !== undefined ? parseInt(req.params.page, 10) : 1,
@ -123,6 +134,8 @@ frontendControllers = {
res.send(feed.xml()); res.send(feed.xml());
}); });
}); });
}).otherwise(function (err) {
return next(new Error(err));
}); });
} }
}; };