Spaces:
Paused
Paused
Download src/utils/error.ts from GraziePrego/deepresearch: direct link, hf CLI and curl.
- Browser
- Download file 687 Bytes
-
https://huggingface.co/spaces/GraziePrego/deepresearch/resolve/main/src/utils/error.ts
- Command line
-
hf download hf://spaces/GraziePrego/deepresearch/src/utils/error.ts
-
curl -L -o error.ts https://huggingface.co/spaces/GraziePrego/deepresearch/resolve/main/src/utils/error.ts
687 Bytes
| import { type APICallError } from "ai"; | |
| import { isString, isObject } from "radash"; | |
| interface GeminiError { | |
| error: { | |
| code: number; | |
| message: string; | |
| status: string; | |
| }; | |
| } | |
| export function parseError(err: unknown): string { | |
| let errorMessage: string = "Unknown Error"; | |
| if (isString(err)) errorMessage = err; | |
| if (isObject(err)) { | |
| const { error } = err as { error: APICallError }; | |
| if (error.responseBody) { | |
| const response = JSON.parse(error.responseBody) as GeminiError; | |
| errorMessage = `[${response.error.status}]: ${response.error.message}`; | |
| } else { | |
| errorMessage = `[${error.name}]: ${error.message}`; | |
| } | |
| } | |
| return errorMessage; | |
| } | |