diff --git a/CHANGELOG.md b/CHANGELOG.md index 49053f9..9578344 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +### Fixed +- Error for empty `restClientConfig` while using HTTP retries. ## [5.5.7] - 2025-12-09 ### Changed diff --git a/__tests__/rest.spec.js b/__tests__/rest.spec.js index ef70c95..7f6bb06 100644 --- a/__tests__/rest.spec.js +++ b/__tests__/rest.spec.js @@ -134,6 +134,26 @@ describe('RestClient', () => { }; expect(retryConfig.retryCondition(timeoutError)).toBe(true); }); + + it('handles undefined restClientConfig without crashing during retries', () => { + const client = new RestClient({ + baseURL: options.baseURL, + headers: options.headers, + restClientConfig: undefined, + }); + + const retryConfig = client.getRetryConfig(); + expect(retryConfig.retries).toBe(6); + + const consoleSpy = jest.spyOn(console, 'log').mockImplementation(); + const onRetry = retryConfig.onRetry; + + expect(() => { + onRetry(1, { code: 'ECONNABORTED' }, { method: 'GET', url: 'http://test.com' }); + }).not.toThrow(); + + consoleSpy.mockRestore(); + }); }); describe('buildPath', () => { diff --git a/lib/rest.js b/lib/rest.js index e8ff4d9..5e3b002 100644 --- a/lib/rest.js +++ b/lib/rest.js @@ -150,7 +150,7 @@ method: ${method}`, getRetryConfig() { const retryOption = this.restClientConfig?.retry; const onRetry = (retryCount, error, requestConfig) => { - if (this.restClientConfig.debug) { + if (this.restClientConfig?.debug) { console.log(`[retry #${retryCount}] ${requestConfig.method?.toUpperCase()} ${requestConfig.url} -> ${error.code || error.message}`); } };