Skip to content

Commit 45b48d7

Browse files
authored
EPMRPP-110786 || Fix error for empty restClientConfig while using http retries (#248)
1 parent 999d824 commit 45b48d7

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
### Fixed
2+
- Error for empty `restClientConfig` while using HTTP retries.
13

24
## [5.5.7] - 2025-12-09
35
### Changed

__tests__/rest.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,26 @@ describe('RestClient', () => {
134134
};
135135
expect(retryConfig.retryCondition(timeoutError)).toBe(true);
136136
});
137+
138+
it('handles undefined restClientConfig without crashing during retries', () => {
139+
const client = new RestClient({
140+
baseURL: options.baseURL,
141+
headers: options.headers,
142+
restClientConfig: undefined,
143+
});
144+
145+
const retryConfig = client.getRetryConfig();
146+
expect(retryConfig.retries).toBe(6);
147+
148+
const consoleSpy = jest.spyOn(console, 'log').mockImplementation();
149+
const onRetry = retryConfig.onRetry;
150+
151+
expect(() => {
152+
onRetry(1, { code: 'ECONNABORTED' }, { method: 'GET', url: 'http://test.com' });
153+
}).not.toThrow();
154+
155+
consoleSpy.mockRestore();
156+
});
137157
});
138158

139159
describe('buildPath', () => {

lib/rest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ method: ${method}`,
150150
getRetryConfig() {
151151
const retryOption = this.restClientConfig?.retry;
152152
const onRetry = (retryCount, error, requestConfig) => {
153-
if (this.restClientConfig.debug) {
153+
if (this.restClientConfig?.debug) {
154154
console.log(`[retry #${retryCount}] ${requestConfig.method?.toUpperCase()} ${requestConfig.url} -> ${error.code || error.message}`);
155155
}
156156
};

0 commit comments

Comments
 (0)