File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,8 +56,8 @@ export class RateLimiter {
5656 return await fn ( ) ;
5757 } catch ( error ) {
5858 // 检查错误字符串中是否包含 429
59- const errorStr = String ( error ) ;
60- if ( this . shouldRetry429 ( op , errorStr ) && i < 10 ) {
59+ const errorStr = String ( error ) . toLowerCase ( ) ;
60+ if ( this . shouldRetry429 ( op , ` ${ errorStr } ` ) && i < 10 ) {
6161 // 遇到 429 错误且未达到重试上限,采用指数退避策略延迟后继续重试
6262 const delay = Math . min ( 2000 * Math . pow ( 2 , i ) , 60000 ) ;
6363 await new Promise ( ( resolve ) => setTimeout ( resolve , delay ) ) ;
@@ -73,8 +73,7 @@ export class RateLimiter {
7373
7474 private shouldRetry429 ( op : string , errorStr : string ) : boolean {
7575 return (
76- ( ( errorStr . includes ( "429" ) && / [ ^ A - Z a - z \d ] 4 2 9 [ ^ A - Z a - z \d ] / . test ( ` ${ errorStr } ` ) ) ||
77- errorStr . toLowerCase ( ) . includes ( "too many requests" ) ) &&
76+ ( ( errorStr . includes ( "429" ) && / [ ^ a - z \d ] 4 2 9 [ ^ a - z \d ] / . test ( errorStr ) ) || errorStr . includes ( "too many requests" ) ) &&
7877 RETRYABLE_429_OPS . has ( op )
7978 ) ;
8079 }
You can’t perform that action at this time.
0 commit comments