From 33d64b0a58e1b0e85136dfce5ad806208d0ab306 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun <phil@kitten.sh> Date: Thu, 16 Mar 2023 14:01:02 +0000 Subject: [PATCH] fix(core): Add alternative rethrow method by wrapping yield (#3063) --- .changeset/silent-numbers-look.md | 5 +++++ packages/core/src/internal/fetchSource.ts | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 .changeset/silent-numbers-look.md diff --git a/.changeset/silent-numbers-look.md b/.changeset/silent-numbers-look.md new file mode 100644 index 0000000000..888b24220b --- /dev/null +++ b/.changeset/silent-numbers-look.md @@ -0,0 +1,5 @@ +--- +'@urql/core': patch +--- + +Ensure network errors are always issued with `CombinedError`s, while downstream errors are re-thrown. diff --git a/packages/core/src/internal/fetchSource.ts b/packages/core/src/internal/fetchSource.ts index efbcc74e32..4345a22b2a 100644 --- a/packages/core/src/internal/fetchSource.ts +++ b/packages/core/src/internal/fetchSource.ts @@ -104,6 +104,7 @@ async function* fetchOperation( url: string, fetchOptions: RequestInit ) { + let networkMode = true; let abortController: AbortController | void; let result: OperationResult | null = null; let response: Response; @@ -132,16 +133,19 @@ async function* fetchOperation( } for await (const payload of results) { - yield (result = result + result = result ? mergeResultPatch(result, payload, response) - : makeResult(operation, payload, response)); + : makeResult(operation, payload, response); + networkMode = false; + yield result; + networkMode = true; } if (!result) { yield (result = makeResult(operation, {}, response)); } } catch (error: any) { - if (result) { + if (!networkMode) { throw error; }