Skip to content

Instantly share code, notes, and snippets.

@e7h4n
Created January 13, 2014 06:43
Show Gist options
  • Select an option

  • Save e7h4n/8395690 to your computer and use it in GitHub Desktop.

Select an option

Save e7h4n/8395690 to your computer and use it in GitHub Desktop.
'use strict';
var exception = require('../lib/exception');
var logger = require('../lib/logger');
var config = require('../lib/config');
/*jshint maxparams: false, unused: false */
module.exports = function (err, req, res, next) {
if (req.path.indexOf('/' + config.get('view').staticUrl) === 0) {
res.send(500, err);
return;
}
if (err.stack) {
logger.error(err.stack);
}
if (err instanceof exception.LOGIN_CONFLICT) {
res.status(406);
return res.redirect('/error/login-conflict');
}
if (err instanceof exception.NOT_FOUND) {
res.status(404);
return res.render('common/page/error/404');
}
if (err instanceof exception.REQUEST_ERROR) {
res.status(err.code);
return res.render('common/page/error/400', {
code: err.code
});
}
if (err instanceof exception.UNAUTHORIZED) {
res.status(401);
return res.render('common/page/error/400', {
code: 401
});
}
res.status(500);
return res.render('common/page/error/500');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment