雪忆
2024-07-29 ecfe66a0199606241c73a52519bbe800c9aa31f8
提交 | 用户 | age
2f6253 1 /**
a821d9 2  * Data processing class, can be configured according to the project
2f6253 3  */
ccaa84 4 import type {
KL 5   AxiosInstance,
6   AxiosRequestConfig,
7   AxiosResponse,
c118e8 8   InternalAxiosRequestConfig,
ccaa84 9 } from 'axios';
4d2fb0 10 import type { RequestOptions, Result } from '#/axios';
2f6253 11
b7ce74 12 export interface CreateAxiosOptions extends AxiosRequestConfig {
b6d5b0 13   authenticationScheme?: string;
b7ce74 14   transform?: AxiosTransform;
V 15   requestOptions?: RequestOptions;
16 }
17
2f6253 18 export abstract class AxiosTransform {
19   /**
ccaa84 20    * A function that is called before a request is sent. It can modify the request configuration as needed.
KL 21    * 在发送请求之前调用的函数。它可以根据需要修改请求配置。
2f6253 22    */
23   beforeRequestHook?: (config: AxiosRequestConfig, options: RequestOptions) => AxiosRequestConfig;
24
25   /**
c0e40f 26    * @description: 处理响应数据
2f6253 27    */
c0e40f 28   transformResponseHook?: (res: AxiosResponse<Result>, options: RequestOptions) => any;
2f6253 29
30   /**
31    * @description: 请求失败处理
32    */
49b66e 33   requestCatchHook?: (e: Error, options: RequestOptions) => Promise<any>;
2f6253 34
35   /**
36    * @description: 请求之前的拦截器
37    */
b6d5b0 38   requestInterceptors?: (
ccaa84 39     config: InternalAxiosRequestConfig,
56a966 40     options: CreateAxiosOptions,
ccaa84 41   ) => InternalAxiosRequestConfig;
2f6253 42
43   /**
44    * @description: 请求之后的拦截器
45    */
46   responseInterceptors?: (res: AxiosResponse<any>) => AxiosResponse<any>;
47
48   /**
49    * @description: 请求之前的拦截器错误处理
50    */
51   requestInterceptorsCatch?: (error: Error) => void;
52
53   /**
54    * @description: 请求之后的拦截器错误处理
55    */
ccaa84 56   responseInterceptorsCatch?: (axiosInstance: AxiosInstance, error: Error) => void;
2f6253 57 }