(error)
| 27 | }; |
| 28 | |
| 29 | export function classifyAPIError(error) { |
| 30 | const status = error?.status; |
| 31 | const message = String(error?.message || error || "").toLowerCase(); |
| 32 | const name = String(error?.name || ""); |
| 33 | |
| 34 | if (name === "AbortError") return API_ERROR.ABORTED; |
| 35 | if (status === 401 || status === 403) return API_ERROR.AUTH_ERROR; |
| 36 | if (status === 404) return API_ERROR.MODEL_NOT_FOUND; |
| 37 | if (status === 429) return API_ERROR.RATE_LIMIT; |
| 38 | if (status === 529 || message.includes("overloaded_error")) return API_ERROR.SERVER_OVERLOAD; |
| 39 | if (status === 413 || message.includes("prompt is too long")) return API_ERROR.PROMPT_TOO_LONG; |
| 40 | if (message.includes("credit balance")) return API_ERROR.CREDIT_BALANCE; |
| 41 | if (message.includes("timeout") || status === 408) return API_ERROR.API_TIMEOUT; |
| 42 | if (message.includes("econn") || message.includes("network") || name.includes("Connection")) { |
| 43 | return API_ERROR.CONNECTION_ERROR; |
| 44 | } |
| 45 | if (typeof status === "number" && status >= 500) return API_ERROR.SERVER_ERROR; |
| 46 | return API_ERROR.UNKNOWN; |
| 47 | } |
| 48 | |
| 49 | export function isPromptTooLongError(error) { |
| 50 | return classifyAPIError(error) === API_ERROR.PROMPT_TOO_LONG; |
no outgoing calls
no test coverage detected