checkStatus.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { useMessage } from '/@/hooks/web/useMessage';
  2. import { userStore } from '/@/store/modules/user';
  3. import { useI18n } from '/@/hooks/web/useI18n';
  4. const { createMessage } = useMessage();
  5. const error = createMessage.error!;
  6. export function checkStatus(status: number, msg: string): void {
  7. const { t } = useI18n();
  8. switch (status) {
  9. case 400:
  10. error(`${msg}`);
  11. break;
  12. // 401: Not logged in
  13. // Jump to the login page if not logged in, and carry the path of the current page
  14. // Return to the current page after successful login. This step needs to be operated on the login page.
  15. case 401:
  16. error(t('sys.api.errMsg401'));
  17. userStore.loginOut(true);
  18. break;
  19. case 403:
  20. error(t('sys.api.errMsg403'));
  21. break;
  22. // 404请求不存在
  23. case 404:
  24. error(t('sys.api.errMsg404'));
  25. break;
  26. case 405:
  27. error(t('sys.api.errMsg405'));
  28. break;
  29. case 408:
  30. error(t('sys.api.errMsg408'));
  31. break;
  32. case 500:
  33. error(t('sys.api.errMsg500'));
  34. break;
  35. case 501:
  36. error(t('sys.api.errMsg501'));
  37. break;
  38. case 502:
  39. error(t('sys.api.errMsg502'));
  40. break;
  41. case 503:
  42. error(t('sys.api.errMsg503'));
  43. break;
  44. case 504:
  45. error(t('sys.api.errMsg504'));
  46. break;
  47. case 505:
  48. error(t('sys.api.errMsg505'));
  49. break;
  50. default:
  51. }
  52. }