mirror of
https://github.com/elder-plinius/G0DM0D3.git
synced 2026-11-16 07:02:25 +00:00
fix: handle Venice error format + expand error classifier
Venice returns {"error": "string"} while OpenRouter returns
{"error": {"message": "..."}}. All three error parse sites
(index.html queryModel, backend queryModel, frontend Venice helper)
now handle both shapes.
Error classifier now catches Venice-specific auth strings:
- "Authentication failed" (Venice bad key)
- "User not found." (OpenRouter bad key)
Diagnostic messages updated to reference both providers.
Verified 7/7 against real API error strings from smoke tests.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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',
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user