fix(parser): wrap parseAnthropicTokenLimitError in try/catch
Add outer try/catch to prevent crashes from non-standard error objects returned by proxy providers (e.g., Antigravity). Add parser tests covering edge cases: circular refs, non-object data fields, invalid JSON in responseBody.
This commit is contained in:
@@ -74,6 +74,14 @@ function isTokenLimitError(text: string): boolean {
|
||||
}
|
||||
|
||||
export function parseAnthropicTokenLimitError(err: unknown): ParsedTokenLimitError | null {
|
||||
try {
|
||||
return parseAnthropicTokenLimitErrorUnsafe(err)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function parseAnthropicTokenLimitErrorUnsafe(err: unknown): ParsedTokenLimitError | null {
|
||||
if (typeof err === "string") {
|
||||
if (err.toLowerCase().includes("non-empty content")) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user