Yuki Takei 6 месяцев назад
Родитель
Сommit
0fb4ce4255
2 измененных файлов с 5 добавлено и 21 удалено
  1. 0 1
      apps/app/src/utils/axios/create-custom-axios.ts
  2. 5 20
      apps/app/src/utils/axios/index.ts

+ 0 - 1
apps/app/src/utils/axios/create-custom-axios.ts

@@ -1,5 +1,4 @@
 import type { AxiosRequestConfig } from 'axios';
-// eslint-disable-next-line no-restricted-imports
 import axios from 'axios';
 import { formatISO } from 'date-fns';
 import qs from 'qs';

+ 5 - 20
apps/app/src/utils/axios/index.ts

@@ -1,31 +1,16 @@
 import type { AxiosStatic } from 'axios';
-// eslint-disable-next-line no-restricted-imports
 import axios from 'axios';
 
 import { createCustomAxios } from './create-custom-axios';
 
-// eslint-disable-next-line no-restricted-imports
 export * from 'axios';
 
-// Expose Axios class to allow class inheritance
-const customAxiosStatic = Object.assign(createCustomAxios(), {
+// Create a new object based on axios, but with custom create method
+// This avoids mutating the original axios object and prevents infinite recursion
+// Order matters: axios static properties first, then custom instance, then override create
+const customAxiosStatic = Object.assign({}, axios, createCustomAxios(), {
+  // Override only the create method
   create: createCustomAxios,
-  Axios: axios.Axios,
-
-  // Expose Cancel & CancelToken
-  Cancel: axios.Cancel,
-
-  CancelToken: axios.CancelToken,
-
-  isCancel: axios.isCancel,
-  VERSION: axios.VERSION,
-
-  // Expose all/spread
-  all: axios.all,
-  spread: axios.spread,
-
-  // Expose isAxiosError
-  isAxiosError: axios.isAxiosError,
 }) satisfies AxiosStatic;
 
 export default customAxiosStatic;