export function getErrorMessage(err: unknown, fallback = "Request failed") {
  if (!err) return fallback;
  if (typeof err === "string") return err;
  if (err instanceof Error) return err.message;
  try {
    // 若你的后端返回 { error: { message } } 或 { message }
    const anyErr = err as any;
    return (
      anyErr?.error?.message ||
      anyErr?.message ||
      JSON.stringify(anyErr)
    );
  } catch {
    return fallback;
  }
}