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 @@
"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;
}