@@ -154,7 +154,14 @@ describe('retryResponseErrorHandler', () => {
154154 } ) ;
155155 it ( 'should call the retry function if retryCondition is passed' , async ( ) => {
156156 const error = {
157- config : { retryOnError : true , retryCount : 4 } ,
157+ config : {
158+ retryOnError : true ,
159+ retryCount : 4 ,
160+ method : 'post' ,
161+ url : '/retryURL' ,
162+ data : { key : 'value' } ,
163+ headers : { 'Content-Type' : 'application/json' }
164+ } ,
158165 response : {
159166 status : 200 ,
160167 statusText : 'Success Response but retry needed' ,
@@ -231,6 +238,103 @@ describe('retryResponseErrorHandler', () => {
231238 expect ( response . status ) . toBe ( 200 ) ;
232239 } ) ;
233240
241+ it ( 'should use configured retryDelay for 429 status retries' , async ( ) => {
242+ const error = {
243+ config : { retryOnError : true , retryCount : 1 } ,
244+ response : {
245+ status : 429 ,
246+ statusText : 'Rate limit exceeded' ,
247+ headers : { } ,
248+ data : {
249+ error_message : 'Rate limit exceeded' ,
250+ error_code : 429 ,
251+ errors : null ,
252+ } ,
253+ } ,
254+ } ;
255+ const config = { retryLimit : 3 , retryDelay : 500 } ;
256+ const client = axios . create ( ) ;
257+
258+ mock . onAny ( ) . reply ( 200 , { success : true } ) ;
259+
260+ jest . useFakeTimers ( ) ;
261+ const startTime = Date . now ( ) ;
262+
263+ const responsePromise = retryResponseErrorHandler ( error , config , client ) ;
264+
265+ // Fast-forward time by the configured delay
266+ jest . advanceTimersByTime ( 500 ) ;
267+
268+ const response = ( await responsePromise ) as AxiosResponse ;
269+ expect ( response . status ) . toBe ( 200 ) ;
270+
271+ jest . useRealTimers ( ) ;
272+ } ) ;
273+
274+ it ( 'should use configured retryDelay for 401 status retries' , async ( ) => {
275+ const error = {
276+ config : { retryOnError : true , retryCount : 1 } ,
277+ response : {
278+ status : 401 ,
279+ statusText : 'Unauthorized' ,
280+ headers : { } ,
281+ data : {
282+ error_message : 'Unauthorized' ,
283+ error_code : 401 ,
284+ errors : null ,
285+ } ,
286+ } ,
287+ } ;
288+ const config = { retryLimit : 3 , retryDelay : 250 } ;
289+ const client = axios . create ( ) ;
290+
291+ mock . onAny ( ) . reply ( 200 , { success : true } ) ;
292+
293+ jest . useFakeTimers ( ) ;
294+
295+ const responsePromise = retryResponseErrorHandler ( error , config , client ) ;
296+
297+ // Fast-forward time by the configured delay
298+ jest . advanceTimersByTime ( 250 ) ;
299+
300+ const response = ( await responsePromise ) as AxiosResponse ;
301+ expect ( response . status ) . toBe ( 200 ) ;
302+
303+ jest . useRealTimers ( ) ;
304+ } ) ;
305+
306+ it ( 'should use default retryDelay (300ms) when not configured for 429 retries' , async ( ) => {
307+ const error = {
308+ config : { retryOnError : true , retryCount : 1 } ,
309+ response : {
310+ status : 429 ,
311+ statusText : 'Rate limit exceeded' ,
312+ headers : { } ,
313+ data : {
314+ error_message : 'Rate limit exceeded' ,
315+ error_code : 429 ,
316+ errors : null ,
317+ } ,
318+ } ,
319+ } ;
320+ const config = { retryLimit : 3 } ; // No retryDelay specified
321+ const client = axios . create ( ) ;
322+
323+ mock . onAny ( ) . reply ( 200 , { success : true } ) ;
324+
325+ jest . useFakeTimers ( ) ;
326+
327+ const responsePromise = retryResponseErrorHandler ( error , config , client ) ;
328+
329+ // Fast-forward time by the default delay (300ms)
330+ jest . advanceTimersByTime ( 300 ) ;
331+
332+ const response = ( await responsePromise ) as AxiosResponse ;
333+ expect ( response . status ) . toBe ( 200 ) ;
334+
335+ jest . useRealTimers ( ) ;
336+ } ) ;
337+
234338 it ( 'should retry when retryCondition is true' , async ( ) => {
235339 const error = {
236340 config : { retryOnError : true , retryCount : 1 } ,
@@ -256,6 +360,40 @@ describe('retryResponseErrorHandler', () => {
256360 expect ( retryCondition ) . toHaveBeenCalledWith ( error ) ;
257361 } ) ;
258362
363+ it ( 'should use configured retryDelay when retryCondition triggers retry' , async ( ) => {
364+ const error = {
365+ config : { retryOnError : true , retryCount : 1 } ,
366+ response : {
367+ status : 500 ,
368+ statusText : 'Internal Server Error' ,
369+ headers : { } ,
370+ data : {
371+ error_message : 'Internal Server Error' ,
372+ error_code : 500 ,
373+ errors : null ,
374+ } ,
375+ } ,
376+ } ;
377+ const retryCondition = jest . fn ( ) . mockReturnValue ( true ) ;
378+ const config = { retryLimit : 3 , retryCondition, retryDelay : 750 } ;
379+ const client = axios . create ( ) ;
380+
381+ mock . onAny ( ) . reply ( 200 , { success : true } ) ;
382+
383+ jest . useFakeTimers ( ) ;
384+
385+ const responsePromise = retryResponseErrorHandler ( error , config , client ) ;
386+
387+ // Fast-forward time by the configured delay
388+ jest . advanceTimersByTime ( 750 ) ;
389+
390+ const response = ( await responsePromise ) as AxiosResponse ;
391+ expect ( response . status ) . toBe ( 200 ) ;
392+ expect ( retryCondition ) . toHaveBeenCalledWith ( error ) ;
393+
394+ jest . useRealTimers ( ) ;
395+ } ) ;
396+
259397 it ( 'should retry with delay when x-ratelimit-remaining is 0 and retry-after header is present' , async ( ) => {
260398 const error = {
261399 config : { retryOnError : true , retryCount : 1 } ,
0 commit comments