Authored by shijian

ajax处理401

... ... @@ -43,24 +43,8 @@ exports.serverError = () => {
if (req.xhr) {
return res.status(401).json(err);
} else if (req.yoho.isApp) {
if (err.lowVersion) {
return res.render('error/app-auth', {
module: 'common',
page: 'app-update',
localCss: true,
message: err.message
});
}
return res.render('error/app-auth', {
module: 'common',
page: 'app-redirect-login',
message: '验证失败,请登录',
localCss: true,
refer: err.refer
});
} else {
return res.redirect(helpers.urlFormat('/signin.html', {
return res.redirect(helpers.urlFormat('/passport/login', {
refer: req.originalUrl
}));
}
... ...
... ... @@ -117,6 +117,7 @@
"yoho-jquery-placeholder": "^2.3.1",
"yoho-jquery-qrcode": "0.0.3",
"yoho-json2": "^1.0.0",
"yoho-cookie": "^1.2.0",
"yoho-slider": "0.0.2"
}
}
\ No newline at end of file
... ...
/**
* 全局引用js
* @author: feng.chen<feng.chen@yoho.cn>
* @date: 2017/03/15
*/
const $ = require('yoho-jquery');
const cookie = require('yoho-cookie');
// 初始化
// 注册ajaxError处理服务端401状态
$(document).ajaxError((event, xhr) => {
if (xhr.status === 401) {
cookie.remove('_UID');
cookie.remove('_TOKEN');
window.location.href = '/passport/login';
}
});
... ...
... ... @@ -29,7 +29,8 @@ shelljs.ls(path.join(__dirname, '/js/**/*.page.js')).forEach((f) => {
'yoho-jquery-placeholder',
'yoho-jquery-qrcode',
'yoho-jquery-dotdotdot',
'xss'
'xss',
path.join(__dirname, '/js/global.js')
];
});
... ...