@google/gemini-cli-core 0.9.0-preview.4 → 0.9.0-preview.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/google-gemini-cli-core-0.9.0-preview.4.tgz +0 -0
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/src/generated/git-commit.d.ts +2 -2
- package/dist/src/generated/git-commit.js +2 -2
- package/dist/src/utils/errorParsing.d.ts +1 -1
- package/dist/src/utils/errorParsing.js +33 -5
- package/dist/src/utils/errorParsing.js.map +1 -1
- package/dist/src/utils/errorParsing.test.js +88 -0
- package/dist/src/utils/errorParsing.test.js.map +1 -1
- package/dist/src/utils/flashFallback.test.js +45 -26
- package/dist/src/utils/flashFallback.test.js.map +1 -1
- package/dist/src/utils/quotaErrorDetection.d.ts +2 -0
- package/dist/src/utils/quotaErrorDetection.js +46 -0
- package/dist/src/utils/quotaErrorDetection.js.map +1 -1
- package/dist/src/utils/retry.js +146 -29
- package/dist/src/utils/retry.js.map +1 -1
- package/dist/src/utils/retry.test.js +110 -31
- package/dist/src/utils/retry.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/src/utils/googleErrors.d.ts +0 -104
- package/dist/src/utils/googleErrors.js +0 -108
- package/dist/src/utils/googleErrors.js.map +0 -1
- package/dist/src/utils/googleErrors.test.d.ts +0 -6
- package/dist/src/utils/googleErrors.test.js +0 -212
- package/dist/src/utils/googleErrors.test.js.map +0 -1
- package/dist/src/utils/googleQuotaErrors.d.ts +0 -35
- package/dist/src/utils/googleQuotaErrors.js +0 -108
- package/dist/src/utils/googleQuotaErrors.js.map +0 -1
- package/dist/src/utils/googleQuotaErrors.test.d.ts +0 -6
- package/dist/src/utils/googleQuotaErrors.test.js +0 -189
- package/dist/src/utils/googleQuotaErrors.test.js.map +0 -1
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -15,5 +15,3 @@ export { makeFakeConfig } from './src/test-utils/config.js';
|
|
|
15
15
|
export * from './src/utils/pathReader.js';
|
|
16
16
|
export { ClearcutLogger } from './src/telemetry/clearcut-logger/clearcut-logger.js';
|
|
17
17
|
export { logModelSlashCommand } from './src/telemetry/loggers.js';
|
|
18
|
-
export * from './src/utils/googleQuotaErrors.js';
|
|
19
|
-
export type { GoogleApiError } from './src/utils/googleErrors.js';
|
package/dist/index.js
CHANGED
|
@@ -15,5 +15,4 @@ export { makeFakeConfig } from './src/test-utils/config.js';
|
|
|
15
15
|
export * from './src/utils/pathReader.js';
|
|
16
16
|
export { ClearcutLogger } from './src/telemetry/clearcut-logger/clearcut-logger.js';
|
|
17
17
|
export { logModelSlashCommand } from './src/telemetry/loggers.js';
|
|
18
|
-
export * from './src/utils/googleQuotaErrors.js';
|
|
19
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,0BAA0B,EAC1B,+BAA+B,EAC/B,8BAA8B,GAC/B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,yBAAyB,GAI1B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,kCAAkC,EAClC,sCAAsC,GACvC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,0BAA0B,EAC1B,+BAA+B,EAC/B,8BAA8B,GAC/B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,yBAAyB,GAI1B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,kCAAkC,EAClC,sCAAsC,GACvC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,oDAAoD,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
export declare const GIT_COMMIT_INFO = "
|
|
7
|
-
export declare const CLI_VERSION = "0.9.0-preview.
|
|
6
|
+
export declare const GIT_COMMIT_INFO = "3b6d90cf";
|
|
7
|
+
export declare const CLI_VERSION = "0.9.0-preview.5";
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
// This file is auto-generated by the build script (scripts/generate-git-commit-info.js)
|
|
7
7
|
// Do not edit this file manually.
|
|
8
|
-
export const GIT_COMMIT_INFO = '
|
|
9
|
-
export const CLI_VERSION = '0.9.0-preview.
|
|
8
|
+
export const GIT_COMMIT_INFO = '3b6d90cf';
|
|
9
|
+
export const CLI_VERSION = '0.9.0-preview.5';
|
|
10
10
|
//# sourceMappingURL=git-commit.js.map
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import
|
|
6
|
+
import { UserTierId } from '../code_assist/types.js';
|
|
7
7
|
import { AuthType } from '../core/contentGenerator.js';
|
|
8
8
|
export declare function parseAndFormatApiError(error: unknown, authType?: AuthType, userTier?: UserTierId, currentModel?: string, fallbackModel?: string): string;
|
|
@@ -3,14 +3,42 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { isApiError, isStructuredError } from './quotaErrorDetection.js';
|
|
7
|
-
import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js';
|
|
6
|
+
import { isProQuotaExceededError, isGenericQuotaExceededError, isApiError, isStructuredError, } from './quotaErrorDetection.js';
|
|
7
|
+
import { DEFAULT_GEMINI_MODEL, DEFAULT_GEMINI_FLASH_MODEL, } from '../config/models.js';
|
|
8
|
+
import { UserTierId } from '../code_assist/types.js';
|
|
8
9
|
import { AuthType } from '../core/contentGenerator.js';
|
|
10
|
+
// Free Tier message functions
|
|
11
|
+
const getRateLimitErrorMessageGoogleFree = (fallbackModel = DEFAULT_GEMINI_FLASH_MODEL) => `\nPossible quota limitations in place or slow response times detected. Switching to the ${fallbackModel} model for the rest of this session.`;
|
|
12
|
+
const getRateLimitErrorMessageGoogleProQuotaFree = (currentModel = DEFAULT_GEMINI_MODEL, fallbackModel = DEFAULT_GEMINI_FLASH_MODEL) => `\nYou have reached your daily ${currentModel} quota limit. You will be switched to the ${fallbackModel} model for the rest of this session. To increase your limits, upgrade to get higher limits at https://goo.gle/set-up-gemini-code-assist, or use /auth to switch to using a paid API key from AI Studio at https://aistudio.google.com/apikey`;
|
|
13
|
+
const getRateLimitErrorMessageGoogleGenericQuotaFree = () => `\nYou have reached your daily quota limit. To increase your limits, upgrade to get higher limits at https://goo.gle/set-up-gemini-code-assist, or use /auth to switch to using a paid API key from AI Studio at https://aistudio.google.com/apikey`;
|
|
14
|
+
// Legacy/Standard Tier message functions
|
|
15
|
+
const getRateLimitErrorMessageGooglePaid = (fallbackModel = DEFAULT_GEMINI_FLASH_MODEL) => `\nPossible quota limitations in place or slow response times detected. Switching to the ${fallbackModel} model for the rest of this session. We appreciate you for choosing Gemini Code Assist and the Gemini CLI.`;
|
|
16
|
+
const getRateLimitErrorMessageGoogleProQuotaPaid = (currentModel = DEFAULT_GEMINI_MODEL, fallbackModel = DEFAULT_GEMINI_FLASH_MODEL) => `\nYou have reached your daily ${currentModel} quota limit. You will be switched to the ${fallbackModel} model for the rest of this session. We appreciate you for choosing Gemini Code Assist and the Gemini CLI. To continue accessing the ${currentModel} model today, consider using /auth to switch to using a paid API key from AI Studio at https://aistudio.google.com/apikey`;
|
|
17
|
+
const getRateLimitErrorMessageGoogleGenericQuotaPaid = (currentModel = DEFAULT_GEMINI_MODEL) => `\nYou have reached your daily quota limit. We appreciate you for choosing Gemini Code Assist and the Gemini CLI. To continue accessing the ${currentModel} model today, consider using /auth to switch to using a paid API key from AI Studio at https://aistudio.google.com/apikey`;
|
|
9
18
|
const RATE_LIMIT_ERROR_MESSAGE_USE_GEMINI = '\nPlease wait and try again later. To increase your limits, request a quota increase through AI Studio, or switch to another /auth method';
|
|
10
19
|
const RATE_LIMIT_ERROR_MESSAGE_VERTEX = '\nPlease wait and try again later. To increase your limits, request a quota increase through Vertex, or switch to another /auth method';
|
|
11
20
|
const getRateLimitErrorMessageDefault = (fallbackModel = DEFAULT_GEMINI_FLASH_MODEL) => `\nPossible quota limitations in place or slow response times detected. Switching to the ${fallbackModel} model for the rest of this session.`;
|
|
12
|
-
function getRateLimitMessage(authType, fallbackModel) {
|
|
21
|
+
function getRateLimitMessage(authType, error, userTier, currentModel, fallbackModel) {
|
|
13
22
|
switch (authType) {
|
|
23
|
+
case AuthType.LOGIN_WITH_GOOGLE: {
|
|
24
|
+
// Determine if user is on a paid tier (Legacy or Standard) - default to FREE if not specified
|
|
25
|
+
const isPaidTier = userTier === UserTierId.LEGACY || userTier === UserTierId.STANDARD;
|
|
26
|
+
if (isProQuotaExceededError(error)) {
|
|
27
|
+
return isPaidTier
|
|
28
|
+
? getRateLimitErrorMessageGoogleProQuotaPaid(currentModel || DEFAULT_GEMINI_MODEL, fallbackModel)
|
|
29
|
+
: getRateLimitErrorMessageGoogleProQuotaFree(currentModel || DEFAULT_GEMINI_MODEL, fallbackModel);
|
|
30
|
+
}
|
|
31
|
+
else if (isGenericQuotaExceededError(error)) {
|
|
32
|
+
return isPaidTier
|
|
33
|
+
? getRateLimitErrorMessageGoogleGenericQuotaPaid(currentModel || DEFAULT_GEMINI_MODEL)
|
|
34
|
+
: getRateLimitErrorMessageGoogleGenericQuotaFree();
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return isPaidTier
|
|
38
|
+
? getRateLimitErrorMessageGooglePaid(fallbackModel)
|
|
39
|
+
: getRateLimitErrorMessageGoogleFree(fallbackModel);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
14
42
|
case AuthType.USE_GEMINI:
|
|
15
43
|
return RATE_LIMIT_ERROR_MESSAGE_USE_GEMINI;
|
|
16
44
|
case AuthType.USE_VERTEX_AI:
|
|
@@ -23,7 +51,7 @@ export function parseAndFormatApiError(error, authType, userTier, currentModel,
|
|
|
23
51
|
if (isStructuredError(error)) {
|
|
24
52
|
let text = `[API Error: ${error.message}]`;
|
|
25
53
|
if (error.status === 429) {
|
|
26
|
-
text += getRateLimitMessage(authType, fallbackModel);
|
|
54
|
+
text += getRateLimitMessage(authType, error, userTier, currentModel, fallbackModel);
|
|
27
55
|
}
|
|
28
56
|
return text;
|
|
29
57
|
}
|
|
@@ -50,7 +78,7 @@ export function parseAndFormatApiError(error, authType, userTier, currentModel,
|
|
|
50
78
|
}
|
|
51
79
|
let text = `[API Error: ${finalMessage} (Status: ${parsedError.error.status})]`;
|
|
52
80
|
if (parsedError.error.code === 429) {
|
|
53
|
-
text += getRateLimitMessage(authType, fallbackModel);
|
|
81
|
+
text += getRateLimitMessage(authType, parsedError, userTier, currentModel, fallbackModel);
|
|
54
82
|
}
|
|
55
83
|
return text;
|
|
56
84
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorParsing.js","sourceRoot":"","sources":["../../../src/utils/errorParsing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"errorParsing.js","sourceRoot":"","sources":["../../../src/utils/errorParsing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,uBAAuB,EACvB,2BAA2B,EAC3B,UAAU,EACV,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,8BAA8B;AAC9B,MAAM,kCAAkC,GAAG,CACzC,gBAAwB,0BAA0B,EAClD,EAAE,CACF,2FAA2F,aAAa,sCAAsC,CAAC;AAEjJ,MAAM,0CAA0C,GAAG,CACjD,eAAuB,oB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AG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAY,CAAC;YACtD,IAAI,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;gBAC5B,IAAI,YAAY,GAAG,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC;gBAC7C,IAAI,CAAC;oBACH,8DAA8D;oBAC9D,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAY,CAAC;oBACxD,IAAI,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;wBAC5B,YAAY,GAAG,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC;oBAC3C,CAAC;gBACH,CAAC;gBAAC,OAAO,EAAE,EAAE,CAAC;oBACZ,kEAAkE;gBACpE,CAAC;gBACD,IAAI,IAAI,GAAG,eAAe,YAAY,aAAa,WAAW,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC;gBAChF,IAAI,WAAW,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,EAAE,CAAC;oBACnC,IAAI,IAAI,mBAAmB,CACzB,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,aAAa,CACd,CAAC;gBACJ,CAAC;gBACD,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC;YACZ,kEAAkE;QACpE,CAAC;QACD,OAAO,eAAe,KAAK,GAAG,CAAC;IACjC,CAAC;IAED,OAAO,yCAAyC,CAAC;AACnD,CAAC"}
|
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { describe, it, expect } from 'vitest';
|
|
7
7
|
import { parseAndFormatApiError } from './errorParsing.js';
|
|
8
|
+
import { isProQuotaExceededError } from './quotaErrorDetection.js';
|
|
8
9
|
import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js';
|
|
10
|
+
import { UserTierId } from '../code_assist/types.js';
|
|
9
11
|
import { AuthType } from '../core/contentGenerator.js';
|
|
10
12
|
describe('parseAndFormatApiError', () => {
|
|
11
13
|
const vertexMessage = 'request a quota increase through Vertex';
|
|
@@ -21,6 +23,12 @@ describe('parseAndFormatApiError', () => {
|
|
|
21
23
|
expect(result).toContain('[API Error: Rate limit exceeded');
|
|
22
24
|
expect(result).toContain('Possible quota limitations in place or slow response times detected. Switching to the gemini-2.5-flash model');
|
|
23
25
|
});
|
|
26
|
+
it('should format a 429 API error with the personal message', () => {
|
|
27
|
+
const errorMessage = 'got status: 429 Too Many Requests. {"error":{"code":429,"message":"Rate limit exceeded","status":"RESOURCE_EXHAUSTED"}}';
|
|
28
|
+
const result = parseAndFormatApiError(errorMessage, AuthType.LOGIN_WITH_GOOGLE, undefined, 'gemini-2.5-pro', DEFAULT_GEMINI_FLASH_MODEL);
|
|
29
|
+
expect(result).toContain('[API Error: Rate limit exceeded');
|
|
30
|
+
expect(result).toContain('Possible quota limitations in place or slow response times detected. Switching to the gemini-2.5-flash model');
|
|
31
|
+
});
|
|
24
32
|
it('should format a 429 API error with the vertex message', () => {
|
|
25
33
|
const errorMessage = 'got status: 429 Too Many Requests. {"error":{"code":429,"message":"Rate limit exceeded","status":"RESOURCE_EXHAUSTED"}}';
|
|
26
34
|
const result = parseAndFormatApiError(errorMessage, AuthType.USE_VERTEX_AI);
|
|
@@ -80,5 +88,85 @@ describe('parseAndFormatApiError', () => {
|
|
|
80
88
|
const expected = '[API Error: An unknown error occurred.]';
|
|
81
89
|
expect(parseAndFormatApiError(error)).toBe(expected);
|
|
82
90
|
});
|
|
91
|
+
it('should format a 429 API error with Pro quota exceeded message for Google auth (Free tier)', () => {
|
|
92
|
+
const errorMessage = 'got status: 429 Too Many Requests. {"error":{"code":429,"message":"Quota exceeded for quota metric \'Gemini 2.5 Pro Requests\' and limit \'RequestsPerDay\' of service \'generativelanguage.googleapis.com\' for consumer \'project_number:123456789\'.","status":"RESOURCE_EXHAUSTED"}}';
|
|
93
|
+
const result = parseAndFormatApiError(errorMessage, AuthType.LOGIN_WITH_GOOGLE, undefined, 'gemini-2.5-pro', DEFAULT_GEMINI_FLASH_MODEL);
|
|
94
|
+
expect(result).toContain("[API Error: Quota exceeded for quota metric 'Gemini 2.5 Pro Requests'");
|
|
95
|
+
expect(result).toContain('You have reached your daily gemini-2.5-pro quota limit');
|
|
96
|
+
expect(result).toContain('upgrade to get higher limits');
|
|
97
|
+
});
|
|
98
|
+
it('should format a regular 429 API error with standard message for Google auth', () => {
|
|
99
|
+
const errorMessage = 'got status: 429 Too Many Requests. {"error":{"code":429,"message":"Rate limit exceeded","status":"RESOURCE_EXHAUSTED"}}';
|
|
100
|
+
const result = parseAndFormatApiError(errorMessage, AuthType.LOGIN_WITH_GOOGLE, undefined, 'gemini-2.5-pro', DEFAULT_GEMINI_FLASH_MODEL);
|
|
101
|
+
expect(result).toContain('[API Error: Rate limit exceeded');
|
|
102
|
+
expect(result).toContain('Possible quota limitations in place or slow response times detected. Switching to the gemini-2.5-flash model');
|
|
103
|
+
expect(result).not.toContain('You have reached your daily gemini-2.5-pro quota limit');
|
|
104
|
+
});
|
|
105
|
+
it('should format a 429 API error with generic quota exceeded message for Google auth', () => {
|
|
106
|
+
const errorMessage = 'got status: 429 Too Many Requests. {"error":{"code":429,"message":"Quota exceeded for quota metric \'GenerationRequests\' and limit \'RequestsPerDay\' of service \'generativelanguage.googleapis.com\' for consumer \'project_number:123456789\'.","status":"RESOURCE_EXHAUSTED"}}';
|
|
107
|
+
const result = parseAndFormatApiError(errorMessage, AuthType.LOGIN_WITH_GOOGLE, undefined, 'gemini-2.5-pro', DEFAULT_GEMINI_FLASH_MODEL);
|
|
108
|
+
expect(result).toContain("[API Error: Quota exceeded for quota metric 'GenerationRequests'");
|
|
109
|
+
expect(result).toContain('You have reached your daily quota limit');
|
|
110
|
+
expect(result).not.toContain('You have reached your daily Gemini 2.5 Pro quota limit');
|
|
111
|
+
});
|
|
112
|
+
it('should prioritize Pro quota message over generic quota message for Google auth', () => {
|
|
113
|
+
const errorMessage = 'got status: 429 Too Many Requests. {"error":{"code":429,"message":"Quota exceeded for quota metric \'Gemini 2.5 Pro Requests\' and limit \'RequestsPerDay\' of service \'generativelanguage.googleapis.com\' for consumer \'project_number:123456789\'.","status":"RESOURCE_EXHAUSTED"}}';
|
|
114
|
+
const result = parseAndFormatApiError(errorMessage, AuthType.LOGIN_WITH_GOOGLE, undefined, 'gemini-2.5-pro', DEFAULT_GEMINI_FLASH_MODEL);
|
|
115
|
+
expect(result).toContain("[API Error: Quota exceeded for quota metric 'Gemini 2.5 Pro Requests'");
|
|
116
|
+
expect(result).toContain('You have reached your daily gemini-2.5-pro quota limit');
|
|
117
|
+
expect(result).not.toContain('You have reached your daily quota limit');
|
|
118
|
+
});
|
|
119
|
+
it('should format a 429 API error with Pro quota exceeded message for Google auth (Standard tier)', () => {
|
|
120
|
+
const errorMessage = 'got status: 429 Too Many Requests. {"error":{"code":429,"message":"Quota exceeded for quota metric \'Gemini 2.5 Pro Requests\' and limit \'RequestsPerDay\' of service \'generativelanguage.googleapis.com\' for consumer \'project_number:123456789\'.","status":"RESOURCE_EXHAUSTED"}}';
|
|
121
|
+
const result = parseAndFormatApiError(errorMessage, AuthType.LOGIN_WITH_GOOGLE, UserTierId.STANDARD, 'gemini-2.5-pro', DEFAULT_GEMINI_FLASH_MODEL);
|
|
122
|
+
expect(result).toContain("[API Error: Quota exceeded for quota metric 'Gemini 2.5 Pro Requests'");
|
|
123
|
+
expect(result).toContain('You have reached your daily gemini-2.5-pro quota limit');
|
|
124
|
+
expect(result).toContain('We appreciate you for choosing Gemini Code Assist and the Gemini CLI');
|
|
125
|
+
expect(result).not.toContain('upgrade to get higher limits');
|
|
126
|
+
});
|
|
127
|
+
it('should format a 429 API error with Pro quota exceeded message for Google auth (Legacy tier)', () => {
|
|
128
|
+
const errorMessage = 'got status: 429 Too Many Requests. {"error":{"code":429,"message":"Quota exceeded for quota metric \'Gemini 2.5 Pro Requests\' and limit \'RequestsPerDay\' of service \'generativelanguage.googleapis.com\' for consumer \'project_number:123456789\'.","status":"RESOURCE_EXHAUSTED"}}';
|
|
129
|
+
const result = parseAndFormatApiError(errorMessage, AuthType.LOGIN_WITH_GOOGLE, UserTierId.LEGACY, 'gemini-2.5-pro', DEFAULT_GEMINI_FLASH_MODEL);
|
|
130
|
+
expect(result).toContain("[API Error: Quota exceeded for quota metric 'Gemini 2.5 Pro Requests'");
|
|
131
|
+
expect(result).toContain('You have reached your daily gemini-2.5-pro quota limit');
|
|
132
|
+
expect(result).toContain('We appreciate you for choosing Gemini Code Assist and the Gemini CLI');
|
|
133
|
+
expect(result).not.toContain('upgrade to get higher limits');
|
|
134
|
+
});
|
|
135
|
+
it('should handle different Gemini 2.5 version strings in Pro quota exceeded errors', () => {
|
|
136
|
+
const errorMessage25 = 'got status: 429 Too Many Requests. {"error":{"code":429,"message":"Quota exceeded for quota metric \'Gemini 2.5 Pro Requests\' and limit \'RequestsPerDay\' of service \'generativelanguage.googleapis.com\' for consumer \'project_number:123456789\'.","status":"RESOURCE_EXHAUSTED"}}';
|
|
137
|
+
const errorMessagePreview = 'got status: 429 Too Many Requests. {"error":{"code":429,"message":"Quota exceeded for quota metric \'Gemini 2.5-preview Pro Requests\' and limit \'RequestsPerDay\' of service \'generativelanguage.googleapis.com\' for consumer \'project_number:123456789\'.","status":"RESOURCE_EXHAUSTED"}}';
|
|
138
|
+
const result25 = parseAndFormatApiError(errorMessage25, AuthType.LOGIN_WITH_GOOGLE, undefined, 'gemini-2.5-pro', DEFAULT_GEMINI_FLASH_MODEL);
|
|
139
|
+
const resultPreview = parseAndFormatApiError(errorMessagePreview, AuthType.LOGIN_WITH_GOOGLE, undefined, 'gemini-2.5-preview-pro', DEFAULT_GEMINI_FLASH_MODEL);
|
|
140
|
+
expect(result25).toContain('You have reached your daily gemini-2.5-pro quota limit');
|
|
141
|
+
expect(resultPreview).toContain('You have reached your daily gemini-2.5-preview-pro quota limit');
|
|
142
|
+
expect(result25).toContain('upgrade to get higher limits');
|
|
143
|
+
expect(resultPreview).toContain('upgrade to get higher limits');
|
|
144
|
+
});
|
|
145
|
+
it('should not match non-Pro models with similar version strings', () => {
|
|
146
|
+
// Test that Flash models with similar version strings don't match
|
|
147
|
+
expect(isProQuotaExceededError("Quota exceeded for quota metric 'Gemini 2.5 Flash Requests' and limit")).toBe(false);
|
|
148
|
+
expect(isProQuotaExceededError("Quota exceeded for quota metric 'Gemini 2.5-preview Flash Requests' and limit")).toBe(false);
|
|
149
|
+
// Test other model types
|
|
150
|
+
expect(isProQuotaExceededError("Quota exceeded for quota metric 'Gemini 2.5 Ultra Requests' and limit")).toBe(false);
|
|
151
|
+
expect(isProQuotaExceededError("Quota exceeded for quota metric 'Gemini 2.5 Standard Requests' and limit")).toBe(false);
|
|
152
|
+
// Test generic quota messages
|
|
153
|
+
expect(isProQuotaExceededError("Quota exceeded for quota metric 'GenerationRequests' and limit")).toBe(false);
|
|
154
|
+
expect(isProQuotaExceededError("Quota exceeded for quota metric 'EmbeddingRequests' and limit")).toBe(false);
|
|
155
|
+
});
|
|
156
|
+
it('should format a generic quota exceeded message for Google auth (Standard tier)', () => {
|
|
157
|
+
const errorMessage = 'got status: 429 Too Many Requests. {"error":{"code":429,"message":"Quota exceeded for quota metric \'GenerationRequests\' and limit \'RequestsPerDay\' of service \'generativelanguage.googleapis.com\' for consumer \'project_number:123456789\'.","status":"RESOURCE_EXHAUSTED"}}';
|
|
158
|
+
const result = parseAndFormatApiError(errorMessage, AuthType.LOGIN_WITH_GOOGLE, UserTierId.STANDARD, 'gemini-2.5-pro', DEFAULT_GEMINI_FLASH_MODEL);
|
|
159
|
+
expect(result).toContain("[API Error: Quota exceeded for quota metric 'GenerationRequests'");
|
|
160
|
+
expect(result).toContain('You have reached your daily quota limit');
|
|
161
|
+
expect(result).toContain('We appreciate you for choosing Gemini Code Assist and the Gemini CLI');
|
|
162
|
+
expect(result).not.toContain('upgrade to get higher limits');
|
|
163
|
+
});
|
|
164
|
+
it('should format a regular 429 API error with standard message for Google auth (Standard tier)', () => {
|
|
165
|
+
const errorMessage = 'got status: 429 Too Many Requests. {"error":{"code":429,"message":"Rate limit exceeded","status":"RESOURCE_EXHAUSTED"}}';
|
|
166
|
+
const result = parseAndFormatApiError(errorMessage, AuthType.LOGIN_WITH_GOOGLE, UserTierId.STANDARD, 'gemini-2.5-pro', DEFAULT_GEMINI_FLASH_MODEL);
|
|
167
|
+
expect(result).toContain('[API Error: Rate limit exceeded');
|
|
168
|
+
expect(result).toContain('We appreciate you for choosing Gemini Code Assist and the Gemini CLI');
|
|
169
|
+
expect(result).not.toContain('upgrade to get higher limits');
|
|
170
|
+
});
|
|
83
171
|
});
|
|
84
172
|
//# sourceMappingURL=errorParsing.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorParsing.test.js","sourceRoot":"","sources":["../../../src/utils/errorParsing.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAGvD,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,MAAM,aAAa,GAAG,yCAAyC,CAAC;IAChE,MAAM,aAAa,GAAG,4CAA4C,CAAC;IAEnE,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC9C,MAAM,YAAY,GAChB,6IAA6I,CAAC;QAChJ,MAAM,QAAQ,GACZ,yFAAyF,CAAC;QAC5F,MAAM,CAAC,sBAAsB,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wDAAwD,EAAE,GAAG,EAAE;QAChE,MAAM,YAAY,GAChB,yHAAyH,CAAC;QAC5H,MAAM,MAAM,GAAG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,CAAC,iBAAiB,EAC1B,UAAU,CAAC,QAAQ,EACnB,gBAAgB,EAChB,0BAA0B,CAC3B,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CACtB,kEAAkE,CACnE,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,yCAAyC,CAAC,CAAC;QACpE,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CACtB,sEAAsE,CACvE,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,8BAA8B,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6FAA6F,EAAE,GAAG,EAAE;QACrG,MAAM,YAAY,GAChB,yHAAyH,CAAC;QAC5H,MAAM,MAAM,GAAG,sBAAsB,CACnC,YAAY,EACZ,QAAQ,CAAC,iBAAiB,EAC1B,UAAU,CAAC,QAAQ,EACnB,gBAAgB,EAChB,0BAA0B,CAC3B,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,iCAAiC,CAAC,CAAC;QAC5D,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CACtB,sEAAsE,CACvE,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,8BAA8B,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -6,16 +6,14 @@
|
|
|
6
6
|
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
7
7
|
import { Config } from '../config/config.js';
|
|
8
8
|
import fs from 'node:fs';
|
|
9
|
-
import { setSimulate429, disableSimulationAfterFallback, shouldSimulate429, resetRequestCounter, } from './testUtils.js';
|
|
9
|
+
import { setSimulate429, disableSimulationAfterFallback, shouldSimulate429, createSimulated429Error, resetRequestCounter, } from './testUtils.js';
|
|
10
10
|
import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js';
|
|
11
11
|
import { retryWithBackoff } from './retry.js';
|
|
12
12
|
import { AuthType } from '../core/contentGenerator.js';
|
|
13
|
-
import { TerminalQuotaError } from './googleQuotaErrors.js';
|
|
14
13
|
vi.mock('node:fs');
|
|
15
14
|
// Update the description to reflect that this tests the retry utility's integration
|
|
16
15
|
describe('Retry Utility Fallback Integration', () => {
|
|
17
16
|
let config;
|
|
18
|
-
let mockGoogleApiError;
|
|
19
17
|
beforeEach(() => {
|
|
20
18
|
vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
21
19
|
vi.mocked(fs.statSync).mockReturnValue({
|
|
@@ -28,11 +26,6 @@ describe('Retry Utility Fallback Integration', () => {
|
|
|
28
26
|
cwd: '/test',
|
|
29
27
|
model: 'gemini-2.5-pro',
|
|
30
28
|
});
|
|
31
|
-
mockGoogleApiError = {
|
|
32
|
-
code: 429,
|
|
33
|
-
message: 'mock error',
|
|
34
|
-
details: [],
|
|
35
|
-
};
|
|
36
29
|
// Reset simulation state for each test
|
|
37
30
|
setSimulate429(false);
|
|
38
31
|
resetRequestCounter();
|
|
@@ -44,49 +37,75 @@ describe('Retry Utility Fallback Integration', () => {
|
|
|
44
37
|
// Use the generalized setter
|
|
45
38
|
config.setFallbackModelHandler(fallbackHandler);
|
|
46
39
|
// Call the handler directly via the config property
|
|
47
|
-
const result = await config.fallbackModelHandler('gemini-2.5-pro', DEFAULT_GEMINI_FLASH_MODEL
|
|
40
|
+
const result = await config.fallbackModelHandler('gemini-2.5-pro', DEFAULT_GEMINI_FLASH_MODEL);
|
|
48
41
|
// Verify it returns the correct intent
|
|
49
42
|
expect(result).toBe('retry');
|
|
50
43
|
});
|
|
51
44
|
// This test validates the retry utility's logic for triggering the callback.
|
|
52
|
-
it('should trigger onPersistent429
|
|
45
|
+
it('should trigger onPersistent429 after 2 consecutive 429 errors for OAuth users', async () => {
|
|
53
46
|
let fallbackCalled = false;
|
|
47
|
+
// Removed fallbackModel variable as it's no longer relevant here.
|
|
48
|
+
// Mock function that simulates exactly 2 429 errors, then succeeds after fallback
|
|
54
49
|
const mockApiCall = vi
|
|
55
50
|
.fn()
|
|
56
|
-
.mockRejectedValueOnce(
|
|
57
|
-
.mockRejectedValueOnce(
|
|
51
|
+
.mockRejectedValueOnce(createSimulated429Error())
|
|
52
|
+
.mockRejectedValueOnce(createSimulated429Error())
|
|
58
53
|
.mockResolvedValueOnce('success after fallback');
|
|
54
|
+
// Mock the onPersistent429 callback (this is what client.ts/geminiChat.ts provides)
|
|
59
55
|
const mockPersistent429Callback = vi.fn(async (_authType) => {
|
|
60
56
|
fallbackCalled = true;
|
|
57
|
+
// Return true to signal retryWithBackoff to reset attempts and continue.
|
|
61
58
|
return true;
|
|
62
59
|
});
|
|
60
|
+
// Test with OAuth personal auth type, with maxAttempts = 2 to ensure fallback triggers
|
|
63
61
|
const result = await retryWithBackoff(mockApiCall, {
|
|
64
62
|
maxAttempts: 2,
|
|
65
63
|
initialDelayMs: 1,
|
|
66
64
|
maxDelayMs: 10,
|
|
65
|
+
shouldRetryOnError: (error) => {
|
|
66
|
+
const status = error.status;
|
|
67
|
+
return status === 429;
|
|
68
|
+
},
|
|
67
69
|
onPersistent429: mockPersistent429Callback,
|
|
68
70
|
authType: AuthType.LOGIN_WITH_GOOGLE,
|
|
69
71
|
});
|
|
72
|
+
// Verify fallback mechanism was triggered
|
|
70
73
|
expect(fallbackCalled).toBe(true);
|
|
71
|
-
expect(mockPersistent429Callback).toHaveBeenCalledWith(AuthType.LOGIN_WITH_GOOGLE, expect.any(
|
|
74
|
+
expect(mockPersistent429Callback).toHaveBeenCalledWith(AuthType.LOGIN_WITH_GOOGLE, expect.any(Error));
|
|
72
75
|
expect(result).toBe('success after fallback');
|
|
76
|
+
// Should have: 2 failures, then fallback triggered, then 1 success after retry reset
|
|
73
77
|
expect(mockApiCall).toHaveBeenCalledTimes(3);
|
|
74
78
|
});
|
|
75
79
|
it('should not trigger onPersistent429 for API key users', async () => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
maxDelayMs: 10,
|
|
84
|
-
onPersistent429: fallbackCallback,
|
|
85
|
-
authType: AuthType.USE_GEMINI, // API key auth type
|
|
80
|
+
let fallbackCalled = false;
|
|
81
|
+
// Mock function that simulates 429 errors
|
|
82
|
+
const mockApiCall = vi.fn().mockRejectedValue(createSimulated429Error());
|
|
83
|
+
// Mock the callback
|
|
84
|
+
const mockPersistent429Callback = vi.fn(async () => {
|
|
85
|
+
fallbackCalled = true;
|
|
86
|
+
return true;
|
|
86
87
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
// Test with API key auth type - should not trigger fallback
|
|
89
|
+
try {
|
|
90
|
+
await retryWithBackoff(mockApiCall, {
|
|
91
|
+
maxAttempts: 5,
|
|
92
|
+
initialDelayMs: 10,
|
|
93
|
+
maxDelayMs: 100,
|
|
94
|
+
shouldRetryOnError: (error) => {
|
|
95
|
+
const status = error.status;
|
|
96
|
+
return status === 429;
|
|
97
|
+
},
|
|
98
|
+
onPersistent429: mockPersistent429Callback,
|
|
99
|
+
authType: AuthType.USE_GEMINI, // API key auth type
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
// Expected to throw after max attempts
|
|
104
|
+
expect(error.message).toContain('Rate limit exceeded');
|
|
105
|
+
}
|
|
106
|
+
// Verify fallback was NOT triggered for API key users
|
|
107
|
+
expect(fallbackCalled).toBe(false);
|
|
108
|
+
expect(mockPersistent429Callback).not.toHaveBeenCalled();
|
|
90
109
|
});
|
|
91
110
|
// This test validates the test utilities themselves.
|
|
92
111
|
it('should properly disable simulation state after fallback (Test Utility)', () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flashFallback.test.js","sourceRoot":"","sources":["../../../src/utils/flashFallback.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAA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I,CAAC;YACH,MAAM,gBAAgB,CAAC,WAAW,EAAE;gBAClC,WAAW,EAAE,CAAC;gBACd,cAAc,EAAE,EAAE;gBAClB,UAAU,EAAE,GAAG;gBACf,kBAAkB,EAAE,CAAC,KAAY,EAAE,EAAE;oBACnC,MAAM,MAAM,GAAI,KAAqC,CAAC,MAAM,CAAC;oBAC7D,OAAO,MAAM,KAAK,GAAG,CAAC;gBACxB,CAAC;gBACD,eAAe,EAAE,yBAAyB;gBAC1C,QAAQ,EAAE,QAAQ,CAAC,UAAU,EAAE,oBAAoB;aACpD,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,uCAAuC;YACvC,MAAM,CAAE,KAAe,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC;QACpE,CAAC;QAED,sDAAsD;QACtD,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnC,MAAM,CAAC,yBAAyB,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IAC3D,CAAC,CAAC,CAAC;IAEH,qDAAqD;IACrD,EAAE,CAAC,wEAAwE,EAAE,GAAG,EAAE;QAChF,oBAAoB;QACpB,cAAc,CAAC,IAAI,CAAC,CAAC;QAErB,+BAA+B;QAC/B,MAAM,CAAC,iBAAiB,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEvC,oCAAoC;QACpC,8BAA8B,EAAE,CAAC;QAEjC,oCAAoC;QACpC,MAAM,CAAC,iBAAiB,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -14,3 +14,5 @@ export interface ApiError {
|
|
|
14
14
|
}
|
|
15
15
|
export declare function isApiError(error: unknown): error is ApiError;
|
|
16
16
|
export declare function isStructuredError(error: unknown): error is StructuredError;
|
|
17
|
+
export declare function isProQuotaExceededError(error: unknown): boolean;
|
|
18
|
+
export declare function isGenericQuotaExceededError(error: unknown): boolean;
|
|
@@ -16,4 +16,50 @@ export function isStructuredError(error) {
|
|
|
16
16
|
'message' in error &&
|
|
17
17
|
typeof error.message === 'string');
|
|
18
18
|
}
|
|
19
|
+
export function isProQuotaExceededError(error) {
|
|
20
|
+
// Check for Pro quota exceeded errors by looking for the specific pattern
|
|
21
|
+
// This will match patterns like:
|
|
22
|
+
// - "Quota exceeded for quota metric 'Gemini 2.5 Pro Requests'"
|
|
23
|
+
// - "Quota exceeded for quota metric 'Gemini 2.5-preview Pro Requests'"
|
|
24
|
+
// We use string methods instead of regex to avoid ReDoS vulnerabilities
|
|
25
|
+
const checkMessage = (message) => message.includes("Quota exceeded for quota metric 'Gemini") &&
|
|
26
|
+
message.includes("Pro Requests'");
|
|
27
|
+
if (typeof error === 'string') {
|
|
28
|
+
return checkMessage(error);
|
|
29
|
+
}
|
|
30
|
+
if (isStructuredError(error)) {
|
|
31
|
+
return checkMessage(error.message);
|
|
32
|
+
}
|
|
33
|
+
if (isApiError(error)) {
|
|
34
|
+
return checkMessage(error.error.message);
|
|
35
|
+
}
|
|
36
|
+
// Check if it's a Gaxios error with response data
|
|
37
|
+
if (error && typeof error === 'object' && 'response' in error) {
|
|
38
|
+
const gaxiosError = error;
|
|
39
|
+
if (gaxiosError.response && gaxiosError.response.data) {
|
|
40
|
+
if (typeof gaxiosError.response.data === 'string') {
|
|
41
|
+
return checkMessage(gaxiosError.response.data);
|
|
42
|
+
}
|
|
43
|
+
if (typeof gaxiosError.response.data === 'object' &&
|
|
44
|
+
gaxiosError.response.data !== null &&
|
|
45
|
+
'error' in gaxiosError.response.data) {
|
|
46
|
+
const errorData = gaxiosError.response.data;
|
|
47
|
+
return checkMessage(errorData.error?.message || '');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
export function isGenericQuotaExceededError(error) {
|
|
54
|
+
if (typeof error === 'string') {
|
|
55
|
+
return error.includes('Quota exceeded for quota metric');
|
|
56
|
+
}
|
|
57
|
+
if (isStructuredError(error)) {
|
|
58
|
+
return error.message.includes('Quota exceeded for quota metric');
|
|
59
|
+
}
|
|
60
|
+
if (isApiError(error)) {
|
|
61
|
+
return error.error.message.includes('Quota exceeded for quota metric');
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
19
65
|
//# sourceMappingURL=quotaErrorDetection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quotaErrorDetection.js","sourceRoot":"","sources":["../../../src/utils/quotaErrorDetection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAO,IAAI,KAAK;QAChB,OAAQ,KAAkB,CAAC,KAAK,KAAK,QAAQ;QAC7C,SAAS,IAAK,KAAkB,CAAC,KAAK,CACvC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,SAAS,IAAI,KAAK;QAClB,OAAQ,KAAyB,CAAC,OAAO,KAAK,QAAQ,CACvD,CAAC;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"quotaErrorDetection.js","sourceRoot":"","sources":["../../../src/utils/quotaErrorDetection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAO,IAAI,KAAK;QAChB,OAAQ,KAAkB,CAAC,KAAK,KAAK,QAAQ;QAC7C,SAAS,IAAK,KAAkB,CAAC,KAAK,CACvC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,i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