refactor(request.ts): 异常msg弹出
Former-commit-id: a46d9d327baa1ca5ffb91ec1342ed1b8e349db61
This commit is contained in:
@@ -7,7 +7,7 @@ import useStore from '@/store';
|
|||||||
const service = axios.create({
|
const service = axios.create({
|
||||||
baseURL: import.meta.env.VITE_APP_BASE_API,
|
baseURL: import.meta.env.VITE_APP_BASE_API,
|
||||||
timeout: 50000,
|
timeout: 50000,
|
||||||
headers: { 'Content-Type': 'application/json;charset=utf-8' },
|
headers: { 'Content-Type': 'application/json;charset=utf-8' }
|
||||||
});
|
});
|
||||||
|
|
||||||
// 请求拦截器
|
// 请求拦截器
|
||||||
@@ -43,23 +43,28 @@ service.interceptors.response.use(
|
|||||||
|
|
||||||
ElMessage({
|
ElMessage({
|
||||||
message: msg || '系统出错',
|
message: msg || '系统出错',
|
||||||
type: 'error',
|
type: 'error'
|
||||||
});
|
});
|
||||||
return Promise.reject(new Error(msg || 'Error'));
|
return Promise.reject(new Error(msg || 'Error'));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(error: any) => {
|
(error: any) => {
|
||||||
if (error.response.data) {
|
if (error.response.data) {
|
||||||
const { code } = error.response.data;
|
const { code, msg } = error.response.data;
|
||||||
// token 过期,重新登录
|
// token 过期,重新登录
|
||||||
if (code === 'A0230') {
|
if (code === 'A0230') {
|
||||||
ElMessageBox.confirm('当前页面已失效,请重新登录', 'Warning', {
|
ElMessageBox.confirm('当前页面已失效,请重新登录', 'Warning', {
|
||||||
confirmButtonText: 'OK',
|
confirmButtonText: 'OK',
|
||||||
type: 'warning',
|
type: 'warning'
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
window.location.href = '/';
|
window.location.href = '/';
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
ElMessage({
|
||||||
|
message: msg || '系统出错',
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Promise.reject(error.message);
|
return Promise.reject(error.message);
|
||||||
|
|||||||
Reference in New Issue
Block a user