Spaces:
Paused
Paused
Download console/src/utils/error.ts from mysticaldragon/HF: direct link, hf CLI and curl.
- Browser
- Download file 691 Bytes
-
https://huggingface.co/spaces/mysticaldragon/HF/resolve/main/console/src/utils/error.ts
- Command line
-
hf download hf://spaces/mysticaldragon/HF/console/src/utils/error.ts
-
curl -L -o error.ts https://huggingface.co/spaces/mysticaldragon/HF/resolve/main/console/src/utils/error.ts
691 Bytes
| export function parseErrorDetail(error: unknown): Record<string, any> | null { | |
| if (!(error instanceof Error)) return null; | |
| const msg = error.message; | |
| // Try " - " separator first (from request.ts formatted errors) | |
| const idx = msg.indexOf(" - "); | |
| if (idx !== -1) { | |
| try { | |
| const parsed = JSON.parse(msg.slice(idx + 3)); | |
| return parsed?.detail || parsed; | |
| } catch { | |
| // fall through to raw JSON attempt | |
| } | |
| } | |
| // Fallback: try parsing the entire message as JSON | |
| try { | |
| const parsed = JSON.parse(msg); | |
| if (typeof parsed === "object" && parsed !== null) { | |
| return parsed?.detail || parsed; | |
| } | |
| } catch { | |
| // not JSON | |
| } | |
| return null; | |
| } | |