/** * @module protopedia/utils/errors/handler * * Error handling utilities for ProtoPedia API calls. * * This module provides the central error handler that transforms various * error scenarios into a consistent {@link FetchPrototypesResult} failure * shape. HTTP normalization is limited to ProtoPedia API errors; all other * errors are classified as network/timeout/abort/unknown. * * Key responsibilities: * - Mapping `PromidasTimeoutError` (timeout) to a TIMEOUT failure. * - Detecting `AbortError` (caller-driven abort) and mapping it to an ABORTED failure. * - Normalizing {@link ProtoPediaApiError} into HTTP failures with status/statusText. * - Preserving network error codes (ENOTFOUND, ECONNREFUSED, etc.) when available. * - Classifying opaque fetch failures (TypeError with well-known messages) as CORS_BLOCKED. * - Ensuring all API errors are normalized into {@link FetchPrototypesResult} * without throwing exceptions. */ import { ProtoPediaApiError } from 'protopedia-api-v2-client'; import type { FetchPrototypesResult } from '../../types/result.types.js'; /** * Normalize a {@link ProtoPediaApiError} into a fetcher HTTP failure result. * * @param error - ProtoPedia API client error containing status and metadata * @returns Failure result with kind 'http' and mapped FetcherErrorCode */ export declare function handleProtoPediaApiError(error: ProtoPediaApiError): FetchPrototypesResult; /** * Normalize non-ProtoPedia errors into fetcher failure results. * * Paths: * - PromidasTimeoutError → timeout/TIMEOUT (no HTTP status) * - AbortError → abort/ABORTED (caller-driven abort, no HTTP status) * - Network-ish errors with code → network/ * - Opaque fetch (known TypeError messages) → cors/CORS_BLOCKED * - Fallback → unknown/UNKNOWN * * Notes: * - Do not trust arbitrary error.status; do not treat non-ProtoPedia errors as HTTP. * - If details.res.code exists, classify as network; otherwise choose cors/unknown. */ export declare function handleNotProtoPediaApiError(error: unknown): FetchPrototypesResult; /** * Normalize any error thrown during ProtoPedia API calls into a * {@link FetchPrototypesResult} failure object. * * Delegation: * - ProtoPediaApiError → {@link handleProtoPediaApiError} (HTTP, preserves status/statusText) * - Others → {@link handleNotProtoPediaApiError} (timeout/abort/network/cors/unknown) * * Notes: * - Only ProtoPediaApiError is treated as trusted HTTP (status/statusText retained). * - If a network code is available, store it in details.res.code and return kind 'network'. * - Known opaque fetch messages (TypeError) are classified as CORS_BLOCKED. */ export declare function handleApiError(error: unknown): FetchPrototypesResult; //# sourceMappingURL=handler.d.ts.map