Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Add alternative rethrow method by wrapping yield #3063

Merged
merged 2 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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