diff --git a/app.js b/app.js index 392456e..20baa9d 100644 --- a/app.js +++ b/app.js @@ -48,17 +48,21 @@ app.configure(function () { })); app.use(issuer.getIssuerConfig()); app.use(app.router); + // if we've fallen through the router, it's a 404 app.use(admin.notFound); }); app.configure('development', function () { + app.get('/500', admin.nextError); app.use(express.errorHandler()); }); +app.configure('production', function () { + app.use(admin.errorHandler); +}); + /** Routes */ -// Route middleware -// ---------------- // Issuer configuration // -------------------- diff --git a/routes/admin.js b/routes/admin.js index e3d5972..9d2c2c7 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -1,6 +1,6 @@ var Badge = require('../models/badge'); var phrases = require('../lib/phrases'); - +var logger = require('../lib/logger'); /* * Administrative Pages */ @@ -141,5 +141,16 @@ exports.userList = function userList(req, res, next) { }; exports.notFound = function notFound(req, res, next) { + res.status(404) return res.render('public/404.html', {}); }; + +exports.nextError = function nextError(req, res, next) { + return next(new Error('some error')); +}; + +exports.errorHandler = function (err, req, res, next) { + logger.error('there was an error at ' + req.url, err); + res.status(500); + return res.render('public/500.html'); +}; diff --git a/views/public/500.html b/views/public/500.html new file mode 100644 index 0000000..389d3ba --- /dev/null +++ b/views/public/500.html @@ -0,0 +1,23 @@ +{% extends "public/layout.html" %} +{% block head %} + +{% endblock %} +{% block body %} +
+
+

Mozilla Webmaker Badges

+
+
+
+ +
+
+

Oh no! Something went wrong

+
+

+ There was a problem trying to do whatever you just tried to + do. Please try again later. +

+

+
+{% endblock %}