@apollo/client
Version:
A fully-featured caching GraphQL client.
1 lines • 3.02 kB
Source Map (JSON)
{"version":3,"file":"LinkError.cjs","sources":["../../../src/errors/LinkError.ts"],"sourcesContent":["import type { ErrorLike } from \"@apollo/client\";\n\nconst registry = new WeakSet<ErrorLike>();\n\n/** @internal Please do not use directly. */\nexport function registerLinkError(error: ErrorLike) {\n registry.add(error);\n}\n\n/**\n * A facade error type that keeps a registry of errors emitted from the link\n * chain. `LinkError` is not an error class itself but rather a utility to\n * detect whether an error originated from the link chain.\n *\n * @remarks\n *\n * Use `LinkError` to distinguish between errors from the link chain and custom\n * errors. This is helpful for retrying an operation at the call site only when\n * the error originates from the link chain.\n *\n * @example\n *\n * The following example creates a custom wrapped query function that detects\n * whether the query includes an operation name and throws if not.\n *\n * ```ts\n * import { LinkError } from \"@apollo/client/errors\";\n *\n * async function runQuery<TData>(query: TypedDocumentNode<TData>) {\n * if (!hasOperationName(query)) {\n * throw new Error(\"Queries should have operation names.\");\n * }\n *\n * return client.watchQuery({ query });\n * }\n *\n * try {\n * const result = await runQuery(query);\n * } catch (error) {\n * // Only log the error if the error wasn't our own custom thrown error\n * if (LinkError.is(error)) {\n * console.log(\"Got network error:\", error.message);\n * }\n * }\n * ```\n */\nexport const LinkError = {\n /**\n * A method that determines whether an error originated from the link chain.\n * `is` does not provide any type narrowing.\n *\n * @example\n *\n * ```ts\n * if (LinkError.is(error)) {\n * // The error originated from the link chain\n * console.log(\"Got network error:\", error.message);\n * }\n * ```\n */\n is: (error: unknown) => registry.has(error as ErrorLike),\n};\n"],"names":[],"mappings":";;;AAKA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,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