error.js 542 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'
        });
    }
    return res.status(err.code || 500).json({
        code: err.code || 500,
        message: '服务器错误!'
    });
};