diff --git a/src/__tests__/client.ts b/src/__tests__/client.ts index 05919200..d97051c8 100644 --- a/src/__tests__/client.ts +++ b/src/__tests__/client.ts @@ -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', ); diff --git a/src/client.ts b/src/client.ts index 728b4e07..2bc66559 100644 --- a/src/client.ts +++ b/src/client.ts @@ -488,9 +488,7 @@ export function createClient< ); }, shouldRetry = isLikeCloseEvent, - isFatalConnectionProblem = (errOrCloseEvent) => - // non `CloseEvent`s are fatal by default - !isLikeCloseEvent(errOrCloseEvent), + isFatalConnectionProblem, on, webSocketImpl, /** @@ -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);