|
@@ -1,7 +1,8 @@
|
|
import Axios from 'axios'
|
|
import Axios from 'axios'
|
|
import { ResCode } from './constant'
|
|
import { ResCode } from './constant'
|
|
|
|
|
|
-import type { AxiosResponse, AxiosRequestConfig } from 'axios'
|
|
|
|
|
|
+import type { AxiosResponse, AxiosRequestConfig, AxiosInstance } from 'axios'
|
|
|
|
+import { setOfflineAxios } from './offline'
|
|
|
|
|
|
export type ResErrorHandler = <D, T extends ResData<D>>(response: AxiosResponse<T>, data?: T) => void
|
|
export type ResErrorHandler = <D, T extends ResData<D>>(response: AxiosResponse<T>, data?: T) => void
|
|
export type ReqErrorHandler = <T>(err: Error, response: AxiosRequestConfig<T>) => void
|
|
export type ReqErrorHandler = <T>(err: Error, response: AxiosRequestConfig<T>) => void
|
|
@@ -11,8 +12,7 @@ export type Hook = {
|
|
after?: (config: AxiosRequestConfig) => void
|
|
after?: (config: AxiosRequestConfig) => void
|
|
}
|
|
}
|
|
|
|
|
|
-export const axiosFactory = () => {
|
|
|
|
- const axiosRaw = Axios.create()
|
|
|
|
|
|
+export const axiosFactory = (axiosRaw: AxiosInstance = Axios.create()) => {
|
|
const axiosConfig = {
|
|
const axiosConfig = {
|
|
token: localStorage.getItem('fuseCodeToken'),
|
|
token: localStorage.getItem('fuseCodeToken'),
|
|
unTokenSet: [] as string[],
|
|
unTokenSet: [] as string[],
|
|
@@ -24,6 +24,10 @@ export const axiosFactory = () => {
|
|
hook: [] as Hook[]
|
|
hook: [] as Hook[]
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if ((window as any).offline) {
|
|
|
|
+ setOfflineAxios(axiosRaw)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
type AxiosConfig = typeof axiosConfig
|
|
type AxiosConfig = typeof axiosConfig
|