Skip to content

Commit

Permalink
Merge pull request #1815 from ErisDS/more-tests
Browse files Browse the repository at this point in the history
Error handling simplification & test improvements
  • Loading branch information
ErisDS committed Jan 3, 2014
2 parents 029a01f + 495b7b7 commit a50f5e1
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 86 deletions.
21 changes: 4 additions & 17 deletions core/server/errorHandling.js
Expand Up @@ -9,17 +9,17 @@ var _ = require('underscore'),
// Paths for views
defaultErrorTemplatePath = path.resolve(configPaths().adminViews, 'user-error.hbs'),
userErrorTemplatePath = path.resolve(configPaths().themePath, 'error.hbs'),
userErrorTemplateExists,
userErrorTemplateExists = false,

ONE_HOUR_S = 60 * 60;

/**
* Basic error handling helpers
*/
errors = {
updateActiveTheme: function (activeTheme) {
updateActiveTheme: function (activeTheme, hasErrorTemplate) {
userErrorTemplatePath = path.resolve(configPaths().themePath, activeTheme, 'error.hbs');
userErrorTemplateExists = undefined;
userErrorTemplateExists = hasErrorTemplate;
},

throwError: function (err) {
Expand Down Expand Up @@ -165,20 +165,7 @@ errors = {
}

// We're not admin and the template doesn't exist. Render the default.
if (userErrorTemplateExists === false) {
return renderErrorInt(defaultErrorTemplatePath);
}

// userErrorTemplateExists is undefined, which means we
// haven't yet checked for it. Do so now!
fs.stat(userErrorTemplatePath, function (err, stat) {
userErrorTemplateExists = !err;
if (userErrorTemplateExists) {
return renderErrorInt();
}

renderErrorInt(defaultErrorTemplatePath);
});
return renderErrorInt(defaultErrorTemplatePath);
},

error404: function (req, res, next) {
Expand Down
2 changes: 1 addition & 1 deletion core/server/middleware/index.js
Expand Up @@ -114,7 +114,7 @@ function activateTheme(activeTheme) {
expressServer.set('theme view engine', hbs.express3(hbsOptions));

// Update user error template
errors.updateActiveTheme(activeTheme);
errors.updateActiveTheme(activeTheme, config.paths().availableThemes[activeTheme].hasOwnProperty('error'));
}

// ### ManageAdminAndTheme Middleware
Expand Down
2 changes: 1 addition & 1 deletion core/test/functional/routes/admin_test.js
Expand Up @@ -39,7 +39,7 @@ describe('Admin Routing', function () {

before(function (done) {
testUtils.clearData().then(function () {
// we initialise data, but not a user. No user should be required for navigating the frontend
// we initialise data, but not a user.
return testUtils.initData();
}).then(function () {
done();
Expand Down

0 comments on commit a50f5e1

Please sign in to comment.