/** * Custom error class for network-layer failures during fetch requests. * * Wraps low-level network errors (connection resets, timeouts, DNS failures, TLS errors, etc.) * with actionable context about what operation failed, which host was targeted, and what remediation * steps may help. * * @example * try { * await client.deploy(); * } catch (error) { * if (error instanceof NetworkError && error.kind === 'timeout') { * console.error('Request timed out, retrying...'); * } * throw error; * } * * @module errors/network-error */ /** * Classification of network error causes. */ export type NetworkErrorKind = 'timeout' | 'connection-reset' | 'connection-refused' | 'dns' | 'tls' | 'aborted' | 'unknown'; /** * Error thrown when a network-layer request fails. * * Provides structured classification of network failures and actionable hints for resolution. */ export declare class NetworkError extends Error { /** * Classified network error kind. */ readonly kind: NetworkErrorKind; /** * Description of the operation that failed (e.g., "WebDAV POST", "OAuth token request"). */ readonly operation?: string; /** * Target hostname (e.g., "sandbox.demandware.net"). */ readonly host?: string; constructor(message: string, options: { kind: NetworkErrorKind; operation?: string; host?: string; cause?: unknown; }); } /** * Classifies a network error by inspecting error properties. * * Checks error name, code (including nested cause.code for undici), and message content * to determine the kind of network failure. * * @param err - The error to classify * @returns Classified error kind */ export declare function classifyNetworkError(err: unknown): NetworkErrorKind; /** * Checks if an error is a network-layer error (not an HTTP/application error). * * Returns true for thrown network errors like "fetch failed", AbortError, TimeoutError, * or errors with recognizable network error codes. * * Returns false for HTTPError and other application-level errors that should pass through untouched. * * @param err - The error to check * @returns true if this is a network error */ export declare function isNetworkError(err: unknown): boolean; /** * Describes a network error kind with human-readable summary and actionable hint. * * @param kind - The network error kind * @returns Summary and hint for the error kind */ export declare function describeNetworkErrorKind(kind: NetworkErrorKind): { summary: string; hint: string; }; /** * Wraps a network error with context about the failed operation and target host. * * If the error is already a NetworkError, returns it as-is (possibly filling in missing context). * If the error is not a network error (e.g., HTTPError), returns it unchanged. * Otherwise, classifies and wraps the error in a NetworkError with an actionable message. * * This function does NOT throw — it returns the wrapped or original error. The caller must throw it. * * @param err - The error to wrap * @param context - Operation and host context for the error * @returns The wrapped NetworkError, or the original error if it's not a network error * * @example * try { * await fetch(url); * } catch (err) { * throw wrapNetworkError(err, { operation: 'OAuth token request', host: 'account.demandware.com' }); * } */ export declare function wrapNetworkError(err: unknown, context: { operation?: string; host?: string; }): NetworkError | unknown;