File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,6 +22,20 @@ export const TELEGRAM_RETRY_DEFAULTS = {
2222const TELEGRAM_RETRY_RE = / 4 2 9 | t i m e o u t | c o n n e c t | r e s e t | c l o s e d | u n a v a i l a b l e | t e m p o r a r i l y / i;
2323const log = createSubsystemLogger ( "retry-policy" ) ;
2424
25+ function resolveTelegramShouldRetry ( params : {
26+ shouldRetry ?: ( err : unknown ) => boolean ;
27+ strictShouldRetry ?: boolean ;
28+ } ) {
29+ if ( ! params . shouldRetry ) {
30+ return ( err : unknown ) => TELEGRAM_RETRY_RE . test ( formatErrorMessage ( err ) ) ;
31+ }
32+ if ( params . strictShouldRetry ) {
33+ return params . shouldRetry ;
34+ }
35+ return ( err : unknown ) =>
36+ params . shouldRetry ?.( err ) || TELEGRAM_RETRY_RE . test ( formatErrorMessage ( err ) ) ;
37+ }
38+
2539function getTelegramRetryAfterMs ( err : unknown ) : number | undefined {
2640 if ( ! err || typeof err !== "object" ) {
2741 return undefined ;
@@ -88,12 +102,7 @@ export function createTelegramRetryRunner(params: {
88102 ...params . configRetry ,
89103 ...params . retry ,
90104 } ) ;
91- const shouldRetry = params . shouldRetry
92- ? params . strictShouldRetry
93- ? params . shouldRetry
94- : ( err : unknown ) =>
95- params . shouldRetry ?.( err ) || TELEGRAM_RETRY_RE . test ( formatErrorMessage ( err ) )
96- : ( err : unknown ) => TELEGRAM_RETRY_RE . test ( formatErrorMessage ( err ) ) ;
105+ const shouldRetry = resolveTelegramShouldRetry ( params ) ;
97106
98107 return < T > ( fn : ( ) => Promise < T > , label ?: string ) =>
99108 retryAsync ( fn , {
You can’t perform that action at this time.
0 commit comments