@@ -641,9 +641,13 @@ function getRetryConfig(
641641function isRetryableFailure ( error : unknown , status ?: number ) : boolean {
642642 if ( status === 429 || ( status && status >= 500 && status <= 599 ) ) return true
643643 if ( error instanceof Error ) {
644+ const code = ( error as NodeJS . ErrnoException ) . code
645+ if ( code === 'ETIMEDOUT' || code === 'ECONNRESET' || code === 'ECONNABORTED' ) {
646+ return true
647+ }
644648 const msg = error . message . toLowerCase ( )
645649 if ( isBodySizeLimitError ( msg ) ) return false
646- return msg . includes ( 'timeout' ) || msg . includes ( 'timed out' ) || msg . includes ( 'econnreset' )
650+ return msg . includes ( 'timeout' ) || msg . includes ( 'timed out' )
647651 }
648652 return false
649653}
@@ -655,8 +659,17 @@ function calculateBackoff(attempt: number, initialDelayMs: number, maxDelayMs: n
655659
656660function parseRetryAfterHeader ( header : string | null ) : number {
657661 if ( ! header ) return 0
658- const seconds = Number . parseInt ( header , 10 )
659- return Number . isFinite ( seconds ) && seconds > 0 ? seconds * 1000 : 0
662+ const trimmed = header . trim ( )
663+ if ( / ^ \d + $ / . test ( trimmed ) ) {
664+ const seconds = Number . parseInt ( trimmed , 10 )
665+ return seconds > 0 ? seconds * 1000 : 0
666+ }
667+ const date = new Date ( trimmed )
668+ if ( ! Number . isNaN ( date . getTime ( ) ) ) {
669+ const deltaMs = date . getTime ( ) - Date . now ( )
670+ return deltaMs > 0 ? deltaMs : 0
671+ }
672+ return 0
660673}
661674
662675/**
0 commit comments