UNPKG

@lodestar/utils

Version:

Utilities required across multiple lodestar packages

74 lines 2.11 kB
/** * Native fetch with transparent and consistent error handling * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/fetch) */ declare function wrappedFetch(url: string | URL, init?: RequestInit): Promise<Response>; export { wrappedFetch as fetch }; export declare function isFetchError(e: unknown): e is FetchError; export type FetchErrorType = "failed" | "input" | "aborted" | "timeout" | "unknown"; type FetchErrorCause = NativeFetchFailedError["cause"] | NativeFetchInputError["cause"]; export declare class FetchError extends Error { type: FetchErrorType; code: string; cause?: FetchErrorCause; constructor(url: string | URL, e: unknown); } type NativeFetchError = TypeError & { cause: Error & { code?: string; }; }; /** * ``` * TypeError: fetch failed * cause: Error: connect ECONNREFUSED 127.0.0.1:9596 * errno: -111, * code: 'ECONNREFUSED', * syscall: 'connect', * address: '127.0.0.1', * port: 9596 * --------------------------- * TypeError: fetch failed * cause: Error: getaddrinfo ENOTFOUND non-existent-domain * errno: -3008, * code: 'ENOTFOUND', * syscall: 'getaddrinfo', * hostname: 'non-existent-domain' * --------------------------- * TypeError: fetch failed * cause: SocketError: other side closed * code: 'UND_ERR_SOCKET', * socket: {} * --------------------------- * TypeError: fetch failed * cause: Error: unknown scheme * [cause]: undefined * ``` */ type NativeFetchFailedError = NativeFetchError & { message: "fetch failed"; cause: { errno?: string; syscall?: string; address?: string; port?: string; hostname?: string; socket?: object; [prop: string]: unknown; }; }; /** * ``` * TypeError: Failed to parse URL from invalid-url * [cause]: TypeError [ERR_INVALID_URL]: Invalid URL * input: 'invalid-url', * code: 'ERR_INVALID_URL' * ``` */ type NativeFetchInputError = NativeFetchError & { cause: { input: unknown; }; }; //# sourceMappingURL=fetch.d.ts.map