Merge remote-tracking branch 'origin/master'

This commit is contained in:
YunaiV 2019-03-11 22:55:04 +08:00
commit 3526a49945

View File

@ -4,6 +4,7 @@ import router from 'umi/router';
import hash from 'hash.js';
import { isAntdPro } from './utils';
import { getLoginToken } from './cache';
import { setAuthority } from './authority';
const codeMessage = {
200: '服务器成功返回请求的数据。',
@ -23,6 +24,14 @@ const codeMessage = {
504: '网关超时。',
};
// 需要调整 login 界面的 code
const redirectLoginCode = {
1002001011: '访问令牌不存在',
1002001012: '访问令牌已过期',
1002001013: '访问令牌已失效',
1002001015: '账号未登陆',
};
function checkStatus(response) {
if (response.status >= 200 && response.status < 300) {
return response;
@ -43,11 +52,17 @@ function checkCode(result) {
if (result.code === undefined || result.code === 0) {
return result;
}
notification.warning({
message: `请求错误 ${result.code}`,
description: result.message,
});
// 重定向到登录界面
if (redirectLoginCode[result.code]) {
setAuthority('');
window.location.reload();
}
const error = new Error(result.message);
error.result = result;
throw error;