MCPcopy Create free account
hub / github.com/anus-dev/ANUS / isProQuotaExceededError

Function isProQuotaExceededError

packages/core/src/utils/quotaErrorDetection.ts:38–85  ·  view source on GitHub ↗
(error: unknown)

Source from the content-addressed store, hash-verified

36}
37
38export function isProQuotaExceededError(error: unknown): boolean {
39 // Check for Pro quota exceeded errors by looking for the specific pattern
40 // This will match patterns like:
41 // - "Quota exceeded for quota metric 'Anus 2.5 Pro Requests'"
42 // - "Quota exceeded for quota metric 'Anus 2.5-preview Pro Requests'"
43 // We use string methods instead of regex to avoid ReDoS vulnerabilities
44
45 const checkMessage = (message: string): boolean =>
46 message.includes("Quota exceeded for quota metric 'Anus") &&
47 message.includes("Pro Requests'");
48
49 if (typeof error === 'string') {
50 return checkMessage(error);
51 }
52
53 if (isStructuredError(error)) {
54 return checkMessage(error.message);
55 }
56
57 if (isApiError(error)) {
58 return checkMessage(error.error.message);
59 }
60
61 // Check if it's a Gaxios error with response data
62 if (error && typeof error === 'object' && 'response' in error) {
63 const gaxiosError = error as {
64 response?: {
65 data?: unknown;
66 };
67 };
68 if (gaxiosError.response && gaxiosError.response.data) {
69 if (typeof gaxiosError.response.data === 'string') {
70 return checkMessage(gaxiosError.response.data);
71 }
72 if (
73 typeof gaxiosError.response.data === 'object' &&
74 gaxiosError.response.data !== null &&
75 'error' in gaxiosError.response.data
76 ) {
77 const errorData = gaxiosError.response.data as {
78 error?: { message?: string };
79 };
80 return checkMessage(errorData.error?.message || '');
81 }
82 }
83 }
84 return false;
85}
86
87export function isGenericQuotaExceededError(error: unknown): boolean {
88 if (typeof error === 'string') {

Callers 4

getRateLimitMessageFunction · 0.85
retryWithBackoffFunction · 0.85
flashFallbackHandlerFunction · 0.85

Calls 3

checkMessageFunction · 0.85
isApiErrorFunction · 0.85
isStructuredErrorFunction · 0.70

Tested by

no test coverage detected