mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-07 11:51:14 -07:00
fix(core): skip telemetry logging for AbortError exceptions (#19477)
Co-authored-by: Yuna Seol <yunaseol@google.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import {
|
||||
isAuthenticationError,
|
||||
isAbortError,
|
||||
UnauthorizedError,
|
||||
toFriendlyError,
|
||||
BadRequestError,
|
||||
@@ -48,6 +49,29 @@ describe('getErrorMessage', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('isAbortError', () => {
|
||||
it('should return true for AbortError', () => {
|
||||
const error = new Error('Aborted');
|
||||
error.name = 'AbortError';
|
||||
expect(isAbortError(error)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true for DOMException AbortError', () => {
|
||||
const error = new DOMException('Aborted', 'AbortError');
|
||||
expect(isAbortError(error)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for other errors', () => {
|
||||
expect(isAbortError(new Error('Other error'))).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for non-error objects', () => {
|
||||
expect(isAbortError({ name: 'AbortError' })).toBe(false);
|
||||
expect(isAbortError(null)).toBe(false);
|
||||
expect(isAbortError('AbortError')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isAuthenticationError', () => {
|
||||
it('should detect error with code: 401 property (MCP SDK style)', () => {
|
||||
const error = { code: 401, message: 'Unauthorized' };
|
||||
|
||||
@@ -26,6 +26,13 @@ export function isNodeError(error: unknown): error is NodeJS.ErrnoException {
|
||||
return error instanceof Error && 'code' in error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an error is an AbortError.
|
||||
*/
|
||||
export function isAbortError(error: unknown): boolean {
|
||||
return error instanceof Error && error.name === 'AbortError';
|
||||
}
|
||||
|
||||
export function getErrorMessage(error: unknown): string {
|
||||
const friendlyError = toFriendlyError(error);
|
||||
if (friendlyError instanceof Error) {
|
||||
|
||||
Reference in New Issue
Block a user