|
1
|
/**
|
Vben
authored
|
2
|
* Data processing class, can be configured according to the project
|
|
3
4
|
*/
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
|
Vben
authored
|
5
|
import type { RequestOptions, Result } from '/#/axios';
|
|
6
|
|
Vben
authored
|
7
|
export interface CreateAxiosOptions extends AxiosRequestConfig {
|
Vben
authored
|
8
|
authenticationScheme?: string;
|
Vben
authored
|
9
10
11
12
|
transform?: AxiosTransform;
requestOptions?: RequestOptions;
}
|
|
13
14
|
export abstract class AxiosTransform {
/**
|
Vben
authored
|
15
|
* @description: Process configuration before request
|
|
16
17
18
19
20
|
* @description: Process configuration before request
*/
beforeRequestHook?: (config: AxiosRequestConfig, options: RequestOptions) => AxiosRequestConfig;
/**
|
Vben
authored
|
21
|
* @description: Request successfully processed
|
|
22
|
*/
|
Vben
authored
|
23
|
transformRequestHook?: (res: AxiosResponse<Result>, options: RequestOptions) => any;
|
|
24
25
26
27
|
/**
* @description: 请求失败处理
*/
|
|
28
|
requestCatchHook?: (e: Error, options: RequestOptions) => Promise<any>;
|
|
29
30
31
32
|
/**
* @description: 请求之前的拦截器
*/
|
Vben
authored
|
33
34
|
requestInterceptors?: (
config: AxiosRequestConfig,
|
vben
authored
|
35
|
options: CreateAxiosOptions,
|
Vben
authored
|
36
|
) => AxiosRequestConfig;
|
|
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
/**
* @description: 请求之后的拦截器
*/
responseInterceptors?: (res: AxiosResponse<any>) => AxiosResponse<any>;
/**
* @description: 请求之前的拦截器错误处理
*/
requestInterceptorsCatch?: (error: Error) => void;
/**
* @description: 请求之后的拦截器错误处理
*/
|
|
51
|
responseInterceptorsCatch?: (axiosInstance: AxiosResponse, error: Error) => void;
|
|
52
|
}
|