/** * Transport envelope shared by feature slices that call the generated Alova * client. Mirrors the backend convention: * `code == HTTP status`, payload in `data`, detail in `error`. */ export interface ApiEnvelope { code: number message: string data?: T | null error?: string | null error_code?: string | null } export class ApiFailure extends Error { readonly code: number readonly errorCode?: string | null constructor(message: string, code: number, errorCode?: string | null) { super(message) this.name = 'ApiFailure' this.code = code this.errorCode = errorCode } } export async function unwrapApi(method: PromiseLike>): Promise { const res = await method if (res.code !== 200) { throw new ApiFailure(res.error || res.message || 'request failed', res.code, res.error_code) } return res.data as T }