error.js 659 Bytes
/**
 * error处理中间件
 * @author: feng.chen<feng.chen@yoho.cn>
 * @date: 2017/04/13
 */
const logger = global.yoho.logger;

module.exports = (err, req, res, next) => { // eslint-disable-line
    logger.error(err);
    if (err.code === 401) {
        return res.status(401).json({
            code: 401,
            message: '抱歉,您暂未登录!',
            redirect: '/signin.html'
        });
    }
    if (err.code === 404) {
        return res.status(404).json({
            code: 404,
            message: 'Not Found'
        });
    }
    return res.status(500).json({
        code: 500,
        message: '服务器错误!'
    });

};