Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ async function run(cmd) {
stdio: ['pipe', 'pipe', 'ignore'],
});
return stdout.trim();
} catch (_e) { // eslint-disable-line @typescript-eslint/no-unused-vars
} catch (_e) {
// eslint-disable-line @typescript-eslint/no-unused-vars
return null;
}
}
Expand Down
18 changes: 17 additions & 1 deletion packages/core/src/utils/googleQuotaErrors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,23 @@ describe('classifyGoogleError', () => {
expect((result as RetryableQuotaError).message).toBe(rawError.message);
});

it('should return original error if code is not 429', () => {
it('should return RetryableQuotaError for 503 Service Unavailable', () => {
const apiError: GoogleApiError = {
code: 503,
message: 'Service Unavailable',
details: [],
};
vi.spyOn(errorParser, 'parseGoogleApiError').mockReturnValue(apiError);
const originalError = new Error('Service Unavailable');
const result = classifyGoogleError(originalError);
expect(result).toBeInstanceOf(RetryableQuotaError);
if (result instanceof RetryableQuotaError) {
expect(result.cause).toBe(apiError);
expect(result.message).toBe('Service Unavailable');
}
});

it('should return original error if code is not 429 or 503', () => {
const apiError: GoogleApiError = {
code: 500,
message: 'Server error',
Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/utils/googleQuotaErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,21 @@ export function classifyGoogleError(error: unknown): unknown {
}
}

// Check for 503 Service Unavailable errors
if (status === 503) {
const errorMessage =
googleApiError?.message ||
(error instanceof Error ? error.message : String(error));
return new RetryableQuotaError(
errorMessage,
googleApiError ?? {
code: 503,
message: errorMessage,
details: [],
},
);
}

if (
!googleApiError ||
googleApiError.code !== 429 ||
Expand Down
Loading