import { isAuthError } from "../api/client";

/**
 * Normalize fetch error handling across hooks.
 */
export function handleFetchError(
  err: unknown,
  setError: (value: string | null) => void,
  fallback: string = "Unknown error",
): void {
  if (err instanceof DOMException && err.name === "AbortError") {
    return;
  }

  if (isAuthError(err)) {
    return;
  }

  setError(err instanceof Error ? err.message : fallback);
}
