import { Interceptors } from "@ice/plugin-request"; import type { AxiosError, AxiosResponse } from "axios"; import { i18n } from 'i18next'; import { CombinedError } from "urql"; interface ReqInterceptorOpts { /** * 签名模式 */ headerMode?: RequestHeaderAuthorizationMode; store: { /** * 获取需要的数据 */ getState: () => { token: string; tenantId: string; }; /** * 获取i18n实例 */ getI18n?: () => i18n; }; /** * 添加额外的headers */ appendHeaders?: () => Record; /** * 登陆地址 */ login?: string; /** * 登陆地址记录当前路由key * 默认值:redirect */ loginRedirectKey?: string; /** * 在header上扩展租户id的key 兼容旧版本 */ tenantIdExtendKeys?: string[]; /** * 异常处理 */ error?: (error: AxiosError | AxiosResponse, errStr?: string, traceId?: string) => void; /** * 异常追踪id的配置 */ errTraceId?: { /** * 是否显示错误traceId */ isShow: boolean; /** * response.status * 默认过滤掉200状态码 如有需要的请自行添加[200,400,...] */ exclusionStatus?: number[]; /** * 支持消息关键词显示 * 由于服务的支持‘内部异常’文案默认进行支持 如有需要的请自行添加['内部异常','特殊提示',...] */ msgKeywords?: string[]; }; } /** * defineRequestConfig 的默认配置 拦截器 * @param option * @returns */ export declare const requestInterceptor: (option: ReqInterceptorOpts) => Interceptors; /** * 针对string去空格处理 * @param obj * @returns */ export declare const trimStringValues: (obj: Record | any[]) => Record; /** * 统一loginUrl的处理 * @param loginUrl */ export declare function goLogin(loginUrl: string, loginRedirectKey?: string): void; /** * 签名模式 */ export declare enum RequestHeaderAuthorizationMode { KO = "ko_hmac" } /** * 根据不同模式获取请求头Authorization的处理 * @param token * @param mode * @returns */ export declare function getRequestHeaderAuthorization(token: string, mode?: RequestHeaderAuthorizationMode): string; export interface KoErr { code?: string | number; message?: string; meta?: Record | (string | number)[]; } /** * 针对ko的异常进行处理 * @param error * @param i18nlang * @returns */ export declare const KoErrFormat: (error?: KoErr, i18nlang?: i18n) => string | undefined; export interface KoAxiosError { errors?: KoErr[]; } /** * 对请求异常进行处理 * @param error * @param errorStr * @returns */ export declare const koErrorFormat: (error: AxiosError | AxiosResponse | CombinedError, i18nlang?: i18n) => string | undefined; /** * 异常traceId的获取 * @param error * @param filters * @returns */ export declare const koErrTraceId: (error: AxiosError | AxiosResponse | CombinedError, filters?: { /** * response.status * 默认过滤掉200状态码 如有需要的请自行添加[200,400,...] */ exclusionStatus?: number[]; /** * 支持消息关键词显示 * 由于服务端的支持‘内部异常’文案默认进行支持 如有需要的请自行添加['内部异常','特殊提示',...] */ msgKeywords?: string[]; }) => string | undefined; export {};