Files
cody-crm/frontend/packages/lib-shared/api/http/axiosTransform.ts
wangziqi 72e2110987
Some checks failed
Synchronize to Gitee / repo-sync (push) Has been cancelled
Typos Checking / Spell Check with Typos (push) Has been cancelled
chore: initial commit
2026-06-23 11:56:23 +08:00

49 lines
1.4 KiB
TypeScript

/**
* 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;
}