{"record":{"id":"3d017e765d08b696","repo":"tonhowtf/omniget","slug":"resposta-nao-e-json","errorCode":null,"errorMessage":"resposta nao e JSON: {}","messagePattern":"resposta nao e JSON: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/ai_keys.rs","lineNumber":363,"sourceCode":"            .await?\n        }\n        _ => {\n            let mut req = c.get(format!(\"{}/models\", entry.base_url));\n            if !entry.key.is_empty() {\n                req = req.bearer_auth(&entry.key);\n            }\n            let resp = req.send().await?;\n            let status = resp.status();\n            let text = resp.text().await.unwrap_or_default();\n            if !status.is_success() {\n                return Err(anyhow!(\n                    \"HTTP {}: {}\",\n                    status.as_u16(),\n                    text.chars().take(200).collect::<String>()\n                ));\n            }\n            serde_json::from_str(&text).map_err(|_| {\n                anyhow!(\n                    \"resposta nao e JSON: {}\",\n                    text.chars().take(120).collect::<String>()\n                )\n            })?\n        }\n    };\n    let arr = json\n        .get(\"data\")\n        .or_else(|| json.get(\"models\"))\n        .and_then(|v| v.as_array())\n        .cloned()\n        .unwrap_or_default();\n    let mut ids: Vec<String> = arr\n        .iter()\n        .filter_map(|m| {\n            m.get(\"id\")\n                .or_else(|| m.get(\"name\"))\n                .and_then(|v| v.as_str())","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/ai_keys.rs#L345-L381","documentation":"After a successful HTTP status, models() parses the response body with serde_json::from_str; if the body is not valid JSON it throws this error with the first 120 characters of the body. This happens when an endpoint returns HTML (login page, error page, Cloudflare challenge) or plain text instead of the expected JSON model list.","triggerScenarios":"Provider endpoint returns 200 but with non-JSON body: HTML login/Cloudflare page, empty body, or plain-text error; base_url pointing at a website rather than an API route.","commonSituations":"base_url misconfigured to the dashboard URL so the server returns the HTML SPA; a proxy/captive portal intercepting requests; provider API returning empty body on some error paths; custom/new-api compatible panels returning HTML for unknown routes.","solutions":["Inspect the 120-char body snippet in the error: HTML tags mean the URL points at a web page, not the API; fix base_url to the correct API route (e.g. /v1/models).","Verify the endpoint returns JSON with curl (curl -H 'Authorization: Bearer KEY' <base>/models).","Check for proxies/VPNs or network middleboxes returning HTML challenge pages.","Confirm the provider is an OpenAI-compatible API and not a plain website panel."],"exampleFix":"// before\nbase_url = \"https://panel.example.com\"          // serves HTML\n// after\nbase_url = \"https://panel.example.com/v1\"       // API route returns JSON","handlingStrategy":"validation","validationCode":"let text = resp.text().await?;\nif text.trim_start().parse::<serde_json::Value>().is_err() {\n    eprintln!(\"endpoint did not return JSON — check base_url points at the API, not the website\");\n}\nlet v: serde_json::Value = serde_json::from_str(&text)?;","typeGuard":"fn looks_like_json(body: &str) -> bool {\n    let t = body.trim_start();\n    t.starts_with('{') || t.starts_with('[')\n}","tryCatchPattern":"match models(id).await {\n    Ok(list) => use(list),\n    Err(e) if e.to_string().starts_with(\"resposta nao e JSON\") => {\n        // body snippet is in the message; fix base_url or inspect for HTML/Cloudflare pages\n        show_misconfigured_url_hint(&e.to_string());\n    }\n    Err(e) => show_error(e),\n}","preventionTips":["Point base_url at the API route, never the dashboard URL","Test endpoints with curl -i to see raw responses","Watch for Cloudflare/login HTML in responses indicating a proxy or wrong URL","Prefer providers with documented JSON APIs"],"tags":["json","http","api"],"backgroundTag":"invalid-json-response","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}