(response: Response, fallback: string)
| 41 | * Extracts a human-readable error message from a Daytona API error response. |
| 42 | */ |
| 43 | export async function extractDaytonaError(response: Response, fallback: string): Promise<string> { |
| 44 | try { |
| 45 | const data = await response.json() |
| 46 | if (typeof data?.message === 'string') return data.message |
| 47 | if (Array.isArray(data?.message)) return data.message.join(', ') |
| 48 | if (typeof data?.error === 'string') return data.error |
| 49 | } catch { |
| 50 | // Non-JSON error body; fall through to the fallback message |
| 51 | } |
| 52 | return `${fallback} (status ${response.status})` |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Coerces an optional user- or LLM-provided value to a number, treating |
no test coverage detected