Blame view

src/utils/http/axios/checkStatus.ts 1.24 KB
陈文彬 authored
1
import { useMessage } from '/@/hooks/web/useMessage';
2
import { userStore } from '/@/store/modules/user';
vben authored
3
import { useI18n } from '/@/hooks/web/useI18n';
陈文彬 authored
4
5
6
7
const { createMessage } = useMessage();

const error = createMessage.error!;
export function checkStatus(status: number, msg: string): void {
vben authored
8
  const { t } = useI18n('sys.api');
陈文彬 authored
9
10
11
12
13
14
15
16
  switch (status) {
    case 400:
      error(`${msg}`);
      break;
    // 401: 未登录
    // 未登录则跳转登录页面,并携带当前页面的路径
    // 在登录成功后返回当前页面,这一步需要在登录页操作。
    case 401:
vben authored
17
      error(t('errMsg401'));
18
      userStore.loginOut(true);
陈文彬 authored
19
20
      break;
    case 403:
vben authored
21
      error(t('errMsg403'));
陈文彬 authored
22
23
24
      break;
    // 404请求不存在
    case 404:
vben authored
25
      error(t('errMsg404'));
陈文彬 authored
26
27
      break;
    case 405:
vben authored
28
      error(t('errMsg405'));
陈文彬 authored
29
30
      break;
    case 408:
vben authored
31
      error(t('errMsg408'));
陈文彬 authored
32
33
      break;
    case 500:
vben authored
34
      error(t('errMsg500'));
陈文彬 authored
35
36
      break;
    case 501:
vben authored
37
      error(t('errMsg501'));
陈文彬 authored
38
39
      break;
    case 502:
vben authored
40
      error(t('errMsg502'));
陈文彬 authored
41
42
      break;
    case 503:
vben authored
43
      error(t('errMsg503'));
陈文彬 authored
44
45
      break;
    case 504:
vben authored
46
      error(t('errMsg504'));
陈文彬 authored
47
48
      break;
    case 505:
vben authored
49
      error(t('errMsg505'));
陈文彬 authored
50
51
52
53
      break;
    default:
  }
}