Skip to content

Commit

Permalink
fix(client): Abort request when reporting error
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Dec 5, 2022
1 parent 0084de7 commit 91057bd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,10 @@ export function createClient<SingleConnection extends boolean = false>(
if (control.signal.aborted) return await complete?.();

// all non-network errors are worth reporting immediately
if (!(err instanceof NetworkError)) throw err;
if (!(err instanceof NetworkError)) {
control.abort(); // TODO: tests for making sure the control's aborted
throw err;
}

// was a network error, get rid of the current connection to ensure retries
// but only if the client is running in lazy mode (otherwise the non-lazy lock will get rid of the connection)
Expand All @@ -591,7 +594,10 @@ export function createClient<SingleConnection extends boolean = false>(
}

// retries are not allowed or we tried to many times, report error
if (!retryAttempts || retries >= retryAttempts) throw err;
if (!retryAttempts || retries >= retryAttempts) {
control.abort(); // TODO: tests for making sure the control's aborted
throw err;
}

// try again
retryingErr = err;
Expand Down

0 comments on commit 91057bd

Please sign in to comment.