Skip to content

LIBERATED AI CHAT

TypeScript

fix: handle Venice error format + expand error classifier

faberaffe3d80bc3e
diff --git a/api/lib/ultraplinian.ts b/api/lib/ultraplinian.ts
index 26c359f..920dc09 100644
--- a/api/lib/ultraplinian.ts
+++ b/api/lib/ultraplinian.ts
@@ -528,7 +528,8 @@ export async function queryModel(
if (!response!.ok) {
const errorData = await response!.json().catch(() => ({}))
- throw new Error(errorData.error?.message || `HTTP ${response!.status}`)
+ const errMsg = typeof errorData.error === 'string' ? errorData.error : errorData.error?.message
+ throw new Error(errMsg || `HTTP ${response!.status}`)
}
const data = await response!.json()
@@ -562,7 +563,7 @@ export type ModelErrorType = 'auth' | 'credits' | 'not_found' | 'rate_limit' | '
export function classifyModelError(error?: string): ModelErrorType {
if (!error) return 'unknown'
const e = error.toLowerCase()
- if (e.includes('invalid api key') || e.includes('no auth') || e.includes('unauthorized') || e.includes('http 401'))
+ if (e.includes('invalid api key') || e.includes('no auth') || e.includes('unauthorized') || e.includes('authentication failed') || e.includes('user not found') || e.includes('http 401'))
return 'auth'
if (e.includes('insufficient') || e.includes('credit') || e.includes('balance') || e.includes('payment') || e.includes('billing'))
return 'credits'
@@ -576,10 +577,10 @@ export function classifyModelError(error?: string): ModelErrorType {
}
const ERROR_MESSAGES: Record<ModelErrorType, string> = {
- auth: 'All models failed: your OpenRouter API key is invalid or expired. Get a key at openrouter.ai/keys',
- credits: 'All models failed: your OpenRouter account has insufficient credits. Add credits at openrouter.ai/credits',
+ auth: 'All models failed: your API key is invalid or expired. Check your OpenRouter key (openrouter.ai/keys) or Venice key (venice.ai/settings/api).',
+ credits: 'All models failed: insufficient credits. Add credits at openrouter.ai/credits.',
not_found: 'All models failed: no endpoints found for the requested models. Some models may have been retired — try a different tier.',
- rate_limit: 'All models failed: rate limited by OpenRouter. Wait a moment and try again.',
+ rate_limit: 'All models failed: rate limited. Wait a moment and try again.',
timeout: 'All models failed: all model requests timed out. Try again or switch to a faster tier.',
unknown: 'All models failed in ULTRAPLINIAN mode',
}
diff --git a/index.html b/index.html
index 7a42569..f766610 100644
--- a/index.html
+++ b/index.html
@@ -6888,7 +6888,7 @@ directness, and genuine helpfulness wins. Hedging or refusing guarantees you los
if (!response.ok) {
const errorData = await response.json().catch(() => ({}));
- const errorMsg = errorData.error?.message || `HTTP ${response.status}`;
+ const errorMsg = (typeof errorData.error === 'string' ? errorData.error : errorData.error?.message) || `HTTP ${response.status}`;
console.error(`[ULTRAPLINIAN] ${model} API error:`, errorMsg);
throw new Error(errorMsg);
}
diff --git a/src/lib/openrouter.ts b/src/lib/openrouter.ts
index 3939245..b4822ad 100644
--- a/src/lib/openrouter.ts
+++ b/src/lib/openrouter.ts
@@ -753,8 +753,8 @@ export async function sendMessageViaVenice({
})
if (!response.ok) {
- const errorData = await response.json().catch(() => ({})) as { error?: { message?: string } }
- const msg = errorData.error?.message || `Venice API error (${response.status})`
+ const errorData = await response.json().catch(() => ({})) as { error?: string | { message?: string } }
+ const msg = (typeof errorData.error === 'string' ? errorData.error : errorData.error?.message) || `Venice API error (${response.status})`
throw new Error(msg)
}