Spaces:
Paused
Paused
Download src/utils/request/axios.ts from imseldrith/chatgpt-web: direct link, hf CLI and curl.
- Browser
- Download file 689 Bytes
-
https://huggingface.co/spaces/imseldrith/chatgpt-web/resolve/main/src/utils/request/axios.ts
- Command line
-
hf download hf://spaces/imseldrith/chatgpt-web/src/utils/request/axios.ts
-
curl -L -o axios.ts https://huggingface.co/spaces/imseldrith/chatgpt-web/resolve/main/src/utils/request/axios.ts
689 Bytes
| import axios, { type AxiosResponse } from 'axios' | |
| import { useAuthStore } from '@/store' | |
| const service = axios.create({ | |
| baseURL: import.meta.env.VITE_GLOB_API_URL, | |
| }) | |
| service.interceptors.request.use( | |
| (config) => { | |
| const token = useAuthStore().token | |
| if (token) | |
| config.headers.Authorization = `Bearer ${token}` | |
| return config | |
| }, | |
| (error) => { | |
| return Promise.reject(error.response) | |
| }, | |
| ) | |
| service.interceptors.response.use( | |
| (response: AxiosResponse): AxiosResponse => { | |
| if (response.status === 200) | |
| return response | |
| throw new Error(response.status.toString()) | |
| }, | |
| (error) => { | |
| return Promise.reject(error) | |
| }, | |
| ) | |
| export default service | |