feat: update
This commit is contained in:
119
utils/network/error.ts
Normal file
119
utils/network/error.ts
Normal file
@@ -0,0 +1,119 @@
|
||||
// import { useTenantStore, useUserStore, useModalStore } from '@star/stores';
|
||||
// import { mb_t } from '@star/languages';
|
||||
// import { router } from '@routers';
|
||||
import { endsWith, includes, startsWith } from 'lodash-es';
|
||||
// import { ModalTypeEnum } from '@star/constants';
|
||||
|
||||
// 错误提示
|
||||
export default class NetworkError {
|
||||
tag: string;
|
||||
key: string;
|
||||
info: string;
|
||||
level: string;
|
||||
origin: string;
|
||||
cmd: string;
|
||||
code: number;
|
||||
logout: boolean;
|
||||
update: boolean;
|
||||
time: string;
|
||||
|
||||
constructor(options: any) {
|
||||
this.tag = '';
|
||||
this.key = '';
|
||||
this.info = '';
|
||||
this.level = '';
|
||||
this.origin = '';
|
||||
this.cmd = '';
|
||||
// this.code = 0
|
||||
this.code = -1;
|
||||
this.logout = false;
|
||||
this.update = false;
|
||||
this.time = new Date().toLocaleString().split('GMT')[0];
|
||||
if (options) {
|
||||
if (options.key) {
|
||||
this.key = options.key;
|
||||
}
|
||||
if (options.tag) {
|
||||
this.tag = options.tag;
|
||||
}
|
||||
if (options.info) {
|
||||
if (startsWith(options.info, '{') && endsWith(options.info, '}')) {
|
||||
const result = JSON.parse(options.info);
|
||||
this.info = result?.msg || result?.exMessage || '';
|
||||
} else {
|
||||
this.info = options.info;
|
||||
}
|
||||
}
|
||||
if (options.level) {
|
||||
this.level = options.level;
|
||||
}
|
||||
if (options.origin) {
|
||||
this.origin = options.origin;
|
||||
}
|
||||
if (options.cmd) {
|
||||
this.cmd = options.cmd;
|
||||
}
|
||||
if (options.code) {
|
||||
this.code = options.code;
|
||||
}
|
||||
if (options.logout) {
|
||||
this.logout = options.logout;
|
||||
}
|
||||
if (options.update) {
|
||||
this.update = options.update;
|
||||
}
|
||||
}
|
||||
// const tenantStore = useTenantStore();
|
||||
// if ([371130, 381119].includes(Number(this.cmd))) {
|
||||
// tenantStore.setRepairStatus(true);
|
||||
// }
|
||||
if (this.info.indexOf('invalid_token') !== -1) {
|
||||
this.info = '亲,麻烦重新登录哦';
|
||||
} else if (this.info.indexOf('Request failed with status code 500') !== -1) {
|
||||
this.info = '网络不给力,请检查网络' + '(500)';
|
||||
} else if (this.info.indexOf('Request failed with status code 502') !== -1) {
|
||||
this.info = '网络不给力,请检查网络' + '(502)';
|
||||
} else if (this.info.indexOf('Error 503 Service Unavailable') !== -1) {
|
||||
this.info = '网络不给力,请检查网络' + '(503)';
|
||||
} else if (this.info.indexOf('Request failed with status code 504') !== -1) {
|
||||
this.info = '网络不给力,请检查网络' + '(504)';
|
||||
} else if (this.info.indexOf('timeout of 20000ms') !== -1) {
|
||||
this.info = '请求超时,请检查网络';
|
||||
} else if (this.info.indexOf('Error 400 Bad Request') !== -1) {
|
||||
this.info = '网络不给力,请重新尝试';
|
||||
} else if (this.info.indexOf('Network Error') !== -1) {
|
||||
this.info = '网络错误,请检查网络';
|
||||
} else if (options?.code === '1115') {
|
||||
// tenantStore.setRepairData(options.origin);
|
||||
// tenantStore.setRepairStatus(true);
|
||||
} else {
|
||||
console.error('err.info:', this.cmd, this.info, options);
|
||||
// this.info = this.info
|
||||
// if (this.info) {
|
||||
// showFailToast(mb_t(this.info));
|
||||
// }
|
||||
// if (this.info && this.info.includes('重新登录')) {
|
||||
// const userStore = useUserStore();
|
||||
// userStore?.clearUserInfo?.();
|
||||
// if (
|
||||
// !startsWith(router.currentRoute.value?.path, '/activity') &&
|
||||
// !includes(['home', 'mine', 'activity'], router.currentRoute.value?.name)
|
||||
// ) {
|
||||
// const modalStore = useModalStore();
|
||||
// const path = router.currentRoute.value?.fullPath;
|
||||
// modalStore.showRegisterModal({ redirect: path });
|
||||
// router.replace?.('/home');
|
||||
// }
|
||||
// }
|
||||
// if (this.info.includes('访问限制')) {
|
||||
// tenantStore.setIPLimitStatus(true);
|
||||
// }
|
||||
// [371130, 370433]返回了请求没有任何数据 才跳维护 其他接口忽略
|
||||
// if ([371130, 370433].includes(Number(this.cmd))) {
|
||||
// // console.log(371130, 370433, this.info, '????????????????????????????');
|
||||
// tenantStore.setRepairStatus(true);
|
||||
// }
|
||||
}
|
||||
// this.info = mb_t(this.info);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user