Skip to content

Commit

Permalink
fix(core): Add alternative rethrow method by wrapping yield (#3063)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten authored Mar 16, 2023
1 parent 9f91c2b commit 33d64b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-numbers-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@urql/core': patch
---

Ensure network errors are always issued with `CombinedError`s, while downstream errors are re-thrown.
10 changes: 7 additions & 3 deletions packages/core/src/internal/fetchSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 33d64b0

Please sign in to comment.