Download src/utils/error.ts from Amiel/deep-researcher: direct link, hf CLI and curl.
- Browser
- Download file 687 Bytes
-
https://huggingface.co/Amiel/deep-researcher/resolve/main/src/utils/error.ts
- Command line
-
hf download hf://Amiel/deep-researcher/src/utils/error.ts
-
curl -L -o error.ts https://huggingface.co/Amiel/deep-researcher/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; | |
| } | |