- 添加需要重定向登陆界面的错误码

This commit is contained in:
sin 2019-03-11 22:45:30 +08:00
parent 0dd5129f83
commit 435951f6c5

View File

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