janhq/jan · error
Unexpected error while fetching models from
Error message
Unexpected error while fetching models from ${provider.provider}: ${error instanceof Error ? error.message : 'Unknown error'} What it means
Generic fallback thrown when fetchModelsFromProvider catches an error that is neither a structured HTTP error nor a fetch/connectivity failure — e.g. response.json() throwing on invalid JSON, an unexpected TypeError, or a non-Error value thrown. The original message is embedded for diagnosis.
Solutions
- Inspect the embedded inner message to identify the original failure.
- curl the /models endpoint and check whether it returns valid JSON (not HTML).
- Fix the proxy/server so a 200 response carries a JSON body.
- Update the local server/provider config to a compatible API version.
Example fix
// before: proxy returns HTML 200 page for /models
// after: exclude /models from the catch-all proxy route
location /v1/ { proxy_pass http://backend; } Defensive patterns
Strategy: try-catch
Type guard
function looksLikeJsonResponse(ct: string | null): boolean {
return !!ct && ct.includes('application/json')
} Try / catch
try {
await fetchModelsFromProvider(provider)
} catch (e) {
if (e instanceof Error && e.message.startsWith('Unexpected error while fetching models')) {
logInnerCause(e.message); suggestServerFix(provider.provider)
}
} Prevention
- Verify the endpoint returns JSON (Content-Type and body) with curl.
- Ensure proxies don't replace API responses with HTML pages.
- Keep local inference servers updated to API-compatible versions.
When it happens
Trigger: response.json() fails because the endpoint returned HTML or invalid JSON; an unexpected runtime TypeError during parsing; a non-Error thrown from fetchTauri whose message lacks 'fetch'.
Common situations: Server returns an HTML error page or empty body with 200; a proxy intercepts the response; a bug in response parsing for a provider with an unusual schema; older server versions returning malformed payloads.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
Related errors
- Failed to parse update response
- ${error.message}
- error.message
- Failed to fetch model catalog
- Failed to fetch models from
AI-assisted analysis of janhq/jan@7205d770c1 (2026-09-17).
Data as JSON: /api/errors/421c0e94ee780540.
Report an issue: GitHub.
Appendix: source
Thrown at web-app/src/services/providers/tauri.ts:278
if (
error instanceof Error &&
structuredErrorPrefixes.some((prefix) =>
(error as Error).message.startsWith(prefix)
)
) {
throw new Error(error.message)
}
// Provide helpful error message for any connection errors
if (error instanceof Error && error.message.includes('fetch')) {
throw new Error(
`Cannot connect to ${provider.provider} at ${provider.base_url}. Please check that the service is running and accessible.`
)
}
// Generic fallback
throw new Error(
`Unexpected error while fetching models from ${provider.provider}: ${error instanceof Error ? error.message : 'Unknown error'}`
)
}
}
async updateSettings(
providerName: string,
settings: ProviderSetting[]
): Promise<void> {
try {
// API keys are persisted to the OS keyring only (via
// register_provider_config), never to the extension's settings.json.
// Blank the key entries at this single chokepoint regardless of caller.
const isSecretKey = (key: string) =>
key === 'api-key' || key === API_KEY_FALLBACKS_SETTING_KEY
return ExtensionManager.getInstance()
.getEngine(providerName)
?.updateSettings(View on GitHub (pinned to 7205d770c1)