| | |
| | | |
| | | import axios from 'axios' |
| | | import { uuidv4 } from '/@/utils/uuid' |
| | | import { CURRENT_CONFIG } from './config' |
| | |
| | | function getAuthToken () { |
| | | return localStorage.getItem(ELocalStorageKey.Token) |
| | | } |
| | | console.log(import.meta.env.VITE_API_URL, 'request.ts') |
| | | const instance = axios.create({ |
| | | // withCredentials: true, |
| | | headers: { |
| | | 'Content-Type': 'application/json', |
| | | }, |
| | | baseURL: import.meta.env.VITE_BASE_API, |
| | | // timeout: 12000, |
| | | }) |
| | | |
| | | instance.interceptors.request.use( |
| | | config => { |
| | | config.headers[ELocalStorageKey.Token] = localStorage.getItem(ELocalStorageKey.Token) |
| | | config.baseURL = import.meta.env.VITE_API_URL |
| | | // config.headers[REQUEST_ID] = uuidv4() |
| | | // config.baseURL = CURRENT_CONFIG.baseURL |
| | | return config |
| | |
| | | } |
| | | // @See: https://github.com/axios/axios/issues/383 |
| | | if (!err.response || !err.response.status) { |
| | | message.error('The network is abnormal, please check the backend service and try again') |
| | | message.error('网络异常,请检查后端服务后重试') |
| | | return |
| | | } |
| | | if (err.response?.status !== 200) { |
| | | message.error(`ERROR_CODE: ${err.response?.status}`) |
| | | message.error(`错误码: ${err.response?.status}`) |
| | | } |
| | | // if (err.response?.status === 403) { |
| | | // // window.location.href = '/' |