| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import axios, {
- AxiosInstance,
- AxiosRequestConfig,
- AxiosResponse,
- AxiosError,
- InternalAxiosRequestConfig
- } from 'axios';
- // API 基础配置
- export const API_CONFIG = {
- BASE_URL: process.env.EXPO_PUBLIC_API_URL,
- // 超时时间
- TIMEOUT: 15000,
-
- // 重试配置
- RETRY: {
- maxRetries: 3,
- retryDelay: 1000,
- },
-
- // 错误消息映射
- ERROR_MESSAGES: {
- NETWORK_ERROR: '网络连接失败,请检查网络设置',
- TIMEOUT_ERROR: '请求超时,请重试',
- SERVER_ERROR: '服务器错误,请稍后重试',
- UNAUTHORIZED: '登录已过期,请重新登录',
- } as const,
- } as const;
- // 基础响应结构
- export interface BaseResponse<T = any> {
- code: number;
- message: string;
- data: T;
- success: boolean;
- }
- // 错误响应结构
- export interface ErrorResponse {
- code: number;
- message: string;
- timestamp?: string;
- path?: string;
- }
- // 请求配置扩展
- export interface RequestConfig {
- needAuth?: boolean; // 是否需要认证
- token?: string | null;
- showError?: boolean; // 是否显示错误提示
- retryCount?: number; // 重试次数
- }
- // 扩展的 Axios 请求配置
- export interface ExtendedRequestConfig extends AxiosRequestConfig {
- customConfig?: RequestConfig;
- }
|