mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-13 07:30:52 -07:00
Co-authored-by: Adam Weidman <65992621+adamfweidman@users.noreply.github.com> Co-authored-by: Sehoon Shon <sshon@google.com> Co-authored-by: Adib234 <30782825+Adib234@users.noreply.github.com> Co-authored-by: Sandy Tao <sandytao520@icloud.com> Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com> Co-authored-by: Aishanee Shah <aishaneeshah@gmail.com> Co-authored-by: gemini-cli-robot <gemini-cli-robot@google.com> Co-authored-by: Gal Zahavi <38544478+galz10@users.noreply.github.com> Co-authored-by: Jacob Richman <jacob314@gmail.com> Co-authored-by: joshualitt <joshualitt@google.com> Co-authored-by: Jenna Inouye <jinouye@google.com>
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2025 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
export interface HttpError extends Error {
|
|
status?: number;
|
|
}
|
|
|
|
/**
|
|
* Extracts the HTTP status code from an error object.
|
|
* @param error The error object.
|
|
* @returns The HTTP status code, or undefined if not found.
|
|
*/
|
|
export function getErrorStatus(error: unknown): number | undefined {
|
|
if (typeof error === 'object' && error !== null) {
|
|
if ('status' in error && typeof error.status === 'number') {
|
|
return error.status;
|
|
}
|
|
// Check for error.response.status (common in axios errors)
|
|
if (
|
|
'response' in error &&
|
|
typeof (error as { response?: unknown }).response === 'object' &&
|
|
(error as { response?: unknown }).response !== null
|
|
) {
|
|
const response = (
|
|
error as { response: { status?: unknown; headers?: unknown } }
|
|
).response;
|
|
if ('status' in response && typeof response.status === 'number') {
|
|
return response.status;
|
|
}
|
|
}
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
export class ModelNotFoundError extends Error {
|
|
code: number;
|
|
constructor(message: string, code?: number) {
|
|
super(message);
|
|
this.name = 'ModelNotFoundError';
|
|
this.code = code ? code : 404;
|
|
}
|
|
}
|