Browse Source

Merge pull request #621 from mhenke/fix/monthly-usage-limit-fallback

Alvin 1 month ago
parent
commit
472fa9eed5

+ 27 - 0
src/hooks/foreground-fallback/index.test.ts

@@ -89,6 +89,33 @@ describe('isRateLimitError', () => {
     expect(isRateLimitError({ message: 'Insufficient balance.' })).toBe(true);
     expect(isRateLimitError({ message: 'Insufficient balance.' })).toBe(true);
   });
   });
 
 
+  test('returns true for "Monthly usage limit reached"', () => {
+    expect(
+      isRateLimitError({
+        message:
+          'Monthly usage limit reached. Resets in X days.',
+      }),
+    ).toBe(true);
+  });
+
+  test('returns true for "5-hour usage limit reached"', () => {
+    expect(
+      isRateLimitError({
+        message:
+          '5-hour usage limit reached. Resets in 36min.',
+      }),
+    ).toBe(true);
+  });
+
+  test('returns true for "Weekly usage limit reached"', () => {
+    expect(
+      isRateLimitError({
+        message:
+          'Weekly usage limit reached. Resets in 2 days.',
+      }),
+    ).toBe(true);
+  });
+
   test('returns false for non-rate-limit error', () => {
   test('returns false for non-rate-limit error', () => {
     expect(isRateLimitError({ message: 'invalid API key' })).toBe(false);
     expect(isRateLimitError({ message: 'invalid API key' })).toBe(false);
   });
   });

+ 3 - 0
src/hooks/foreground-fallback/index.ts

@@ -43,6 +43,9 @@ const RATE_LIMIT_PATTERNS = [
   /insufficient.?(quota|balance)/i,
   /insufficient.?(quota|balance)/i,
   /high concurrency/i,
   /high concurrency/i,
   /reduce concurrency/i,
   /reduce concurrency/i,
+  /monthly usage limit/i,
+  /5-hour usage limit/i,
+  /weekly usage limit/i,
 ];
 ];
 
 
 export function isRateLimitError(error: unknown): boolean {
 export function isRateLimitError(error: unknown): boolean {