Skip to content

Commit

Permalink
fix(client): isFatalConnectionProblem defaults to undefined for usi…
Browse files Browse the repository at this point in the history
…ng `shouldRetry`
  • Loading branch information
enisdenjo committed Apr 25, 2022
1 parent f30de49 commit 9d5c573
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
20 changes: 20 additions & 0 deletions src/__tests__/client.ts
Expand Up @@ -1702,6 +1702,26 @@ describe('reconnecting', () => {
}, 20);
});

it('should allow retrying non-CloseEvent connection problems', async (done) => {
let count = 0;
createClient({
url: 'ws://idontexitst.no',
lazy: false,
retryAttempts: 1,
retryWait: () => Promise.resolve(),
onNonLazyError: noop,
shouldRetry: () => true,
on: {
connecting: () => {
count++;
if (count === 2) {
done();
}
},
},
});
});

it.todo(
'should attempt reconnecting silently a few times before closing for good',
);
Expand Down
6 changes: 2 additions & 4 deletions src/client.ts
Expand Up @@ -488,9 +488,7 @@ export function createClient<
);
},
shouldRetry = isLikeCloseEvent,
isFatalConnectionProblem = (errOrCloseEvent) =>
// non `CloseEvent`s are fatal by default
!isLikeCloseEvent(errOrCloseEvent),
isFatalConnectionProblem,
on,
webSocketImpl,
/**
Expand Down Expand Up @@ -849,7 +847,7 @@ export function createClient<
if (!shouldRetry(errOrCloseEvent)) throw errOrCloseEvent;

// @deprecated throw fatal connection problems immediately
if (isFatalConnectionProblem(errOrCloseEvent)) throw errOrCloseEvent;
if (isFatalConnectionProblem?.(errOrCloseEvent)) throw errOrCloseEvent;

// looks good, start retrying
return (retrying = true);
Expand Down

0 comments on commit 9d5c573

Please sign in to comment.