fix: remove direct gaxios dependency (#4289)

This commit is contained in:
Pascal Birchler
2025-07-18 00:54:19 +02:00
committed by GitHub
parent 695afac33e
commit 4b8838bea4
5 changed files with 18 additions and 118 deletions

View File

@@ -33,7 +33,6 @@
"command-exists": "^1.2.9",
"diff": "^7.0.0",
"dotenv": "^17.1.0",
"gaxios": "^7.1.1",
"glob": "^10.4.1",
"highlight.js": "^11.11.1",
"ink": "^6.0.1",

View File

@@ -4,7 +4,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { GaxiosError } from 'gaxios';
import { useState, useEffect, useCallback } from 'react';
import { Config, CodeAssistServer, UserTierId } from '@google/gemini-cli-core';
@@ -113,13 +112,18 @@ async function getRemoteDataCollectionOptIn(
try {
const resp = await server.getCodeAssistGlobalUserSetting();
return resp.freeTierDataCollectionOptin;
} catch (e) {
if (e instanceof GaxiosError) {
if (e.response?.status === 404) {
} catch (error: unknown) {
if (error && typeof error === 'object' && 'response' in error) {
const gaxiosError = error as {
response?: {
status?: unknown;
};
};
if (gaxiosError.response?.status === 404) {
return true;
}
}
throw e;
throw error;
}
}

View File

@@ -33,7 +33,6 @@
"ajv": "^8.17.1",
"diff": "^7.0.0",
"dotenv": "^17.1.0",
"gaxios": "^7.1.1",
"glob": "^10.4.5",
"google-auth-library": "^9.11.0",
"html-to-text": "^9.0.5",

View File

@@ -4,7 +4,11 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { GaxiosError } from 'gaxios';
interface GaxiosError {
response?: {
data?: unknown;
};
}
export function isNodeError(error: unknown): error is NodeJS.ErrnoException {
return error instanceof Error && 'code' in error;
@@ -33,8 +37,9 @@ interface ResponseData {
}
export function toFriendlyError(error: unknown): unknown {
if (error instanceof GaxiosError) {
const data = parseResponseData(error);
if (error && typeof error === 'object' && 'response' in error) {
const gaxiosError = error as GaxiosError;
const data = parseResponseData(gaxiosError);
if (data.error && data.error.message && data.error.code) {
switch (data.error.code) {
case 400:
@@ -58,5 +63,5 @@ function parseResponseData(error: GaxiosError): ResponseData {
if (typeof error.response?.data === 'string') {
return JSON.parse(error.response?.data) as ResponseData;
}
return typeof error.response?.data as ResponseData;
return error.response?.data as ResponseData;
}