vue-vben-admin/src/utils/http/axios/axiosTransform.ts

53 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-09-28 20:19:10 +08:00
/**
2021-02-26 22:45:36 +08:00
* Data processing class, can be configured according to the project
2020-09-28 20:19:10 +08:00
*/
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
import type { RequestOptions, Result } from '/#/axios';
2020-09-28 20:19:10 +08:00
export interface CreateAxiosOptions extends AxiosRequestConfig {
authenticationScheme?: string;
transform?: AxiosTransform;
requestOptions?: RequestOptions;
}
2020-09-28 20:19:10 +08:00
export abstract class AxiosTransform {
/**
2021-02-26 22:45:36 +08:00
* @description: Process configuration before request
2020-09-28 20:19:10 +08:00
* @description: Process configuration before request
*/
beforeRequestHook?: (config: AxiosRequestConfig, options: RequestOptions) => AxiosRequestConfig;
/**
2021-02-26 22:45:36 +08:00
* @description: Request successfully processed
2020-09-28 20:19:10 +08:00
*/
2021-02-26 22:45:36 +08:00
transformRequestHook?: (res: AxiosResponse<Result>, options: RequestOptions) => any;
2020-09-28 20:19:10 +08:00
/**
* @description:
*/
requestCatchHook?: (e: Error, options: RequestOptions) => Promise<any>;
2020-09-28 20:19:10 +08:00
/**
* @description:
*/
requestInterceptors?: (
config: AxiosRequestConfig,
2021-08-24 22:41:48 +08:00
options: CreateAxiosOptions,
) => AxiosRequestConfig;
2020-09-28 20:19:10 +08:00
/**
* @description:
*/
responseInterceptors?: (res: AxiosResponse<any>) => AxiosResponse<any>;
/**
* @description:
*/
requestInterceptorsCatch?: (error: Error) => void;
/**
* @description:
*/
2022-03-19 00:07:34 +08:00
responseInterceptorsCatch?: (axiosInstance: AxiosResponse, error: Error) => void;
2020-09-28 20:19:10 +08:00
}