import axios from "axios"; export function extractError(err: unknown): string { if (axios.isAxiosError(err)) { const status = err.response?.status; const data = err.response?.data; if (data) { const body = typeof data === "string" ? data.slice(0, 200) : (data?.message ?? data?.error ?? JSON.stringify(data)).toString().slice(0, 200); return status ? `HTTP ${status}: ${body}` : body; } if (status) return `HTTP ${status} — ${err.message}`; if (err.code === "ECONNABORTED") return "Request timed out. Check that the URL is reachable."; if (err.message) return err.message; } if (err instanceof Error) return err.message; return "Unknown error"; }