Created
January 13, 2014 06:43
-
-
Save e7h4n/8395690 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| '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