chore: initial commit
This commit is contained in:
48
frontend/packages/lib-shared/api/http/axiosTransform.ts
Normal file
48
frontend/packages/lib-shared/api/http/axiosTransform.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Data processing class, can be configured according to the project
|
||||
*/
|
||||
import type { RequestOptions, Result } from '../../types/axios';
|
||||
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||
|
||||
export abstract class AxiosTransform {
|
||||
/**
|
||||
* @description: 请求之前处理配置
|
||||
*/
|
||||
beforeRequestHook?: (config: AxiosRequestConfig, options: RequestOptions) => AxiosRequestConfig;
|
||||
|
||||
/**
|
||||
* @description: 处理请求数据。如果数据不是预期格式,可直接抛出错
|
||||
*/
|
||||
transformRequestHook?: (res: AxiosResponse<Result>, options: RequestOptions) => any;
|
||||
|
||||
/**
|
||||
* @description: 请求之前的拦截器
|
||||
*/
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
requestInterceptors?: (config: AxiosRequestConfig, options: CreateAxiosOptions) => AxiosRequestConfig;
|
||||
|
||||
/**
|
||||
* @description: 请求之后的拦截器
|
||||
*/
|
||||
responseInterceptors?: (res: AxiosResponse<any>) => AxiosResponse<any>;
|
||||
|
||||
/**
|
||||
* @description: 请求之后的拦截器错误处理
|
||||
*/
|
||||
responseInterceptorsCatch?: (error: Error) => void;
|
||||
}
|
||||
|
||||
export interface CreateAxiosOptions extends AxiosRequestConfig {
|
||||
authenticationScheme?: string;
|
||||
transform?: AxiosTransform;
|
||||
requestOptions?: RequestOptions;
|
||||
useAppStore?: any;
|
||||
showErrorMsg?: (options: any) => void;
|
||||
checkStatus?: (
|
||||
status: number,
|
||||
msg: string,
|
||||
msgDetail: string | Record<string, any>,
|
||||
code?: number,
|
||||
noErrorTip?: boolean
|
||||
) => void;
|
||||
}
|
||||
Reference in New Issue
Block a user