{"record":{"id":"b9162eb373c018db","repo":"tonhowtf/omniget","slug":"erro-ao-processar-resposta-do-tiktok","errorCode":null,"errorMessage":"Erro ao processar resposta do TikTok","messagePattern":"Erro ao processar resposta do TikTok","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/platforms/tiktok.rs","lineNumber":171,"sourceCode":"            *self.captured_cookies.lock().await = Some(cookie_str);\n        }\n\n        let html = response.text().await?;\n\n        if Self::is_captcha_page(&html) {\n            return Err(anyhow!(\n                \"TikTok is blocking requests. Try again in a few minutes.\"\n            ));\n        }\n\n        let json_str = html\n            .split(\"<script id=\\\"__UNIVERSAL_DATA_FOR_REHYDRATION__\\\" type=\\\"application/json\\\">\")\n            .nth(1)\n            .and_then(|s| s.split(\"</script>\").next())\n            .ok_or_else(|| anyhow!(\"TikTok is blocking requests. Try again in a few minutes.\"))?;\n\n        let data: serde_json::Value = serde_json::from_str(json_str)\n            .map_err(|_| anyhow!(\"Erro ao processar resposta do TikTok\"))?;\n\n        let video_detail = data\n            .get(\"__DEFAULT_SCOPE__\")\n            .and_then(|s| s.get(\"webapp.video-detail\"))\n            .ok_or_else(|| anyhow!(\"Video data not found in TikTok response\"))?;\n\n        if let Some(status_msg) = video_detail\n            .get(\"statusMsg\")\n            .and_then(|v| v.as_str())\n            .filter(|s| !s.is_empty())\n        {\n            return Err(anyhow!(\"Post not available: {}\", status_msg));\n        }\n\n        if let Some(status_code) = video_detail.get(\"statusCode\").and_then(|v| v.as_u64()) {\n            if status_code != 0 {\n                return Err(anyhow!(\"Post not available (status {})\", status_code));\n            }","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/platforms/tiktok.rs#L153-L189","documentation":"The TikTok HTML page was fetched, but the JSON embedded in the __UNIVERSAL_DATA_FOR_REHYDRATION__ script tag could not be parsed by serde_json. This means TikTok served a page whose rehydration payload is malformed, truncated, or not JSON (e.g. a captcha/interstitial page). The library throws it instead of panicking on from_str.","triggerScenarios":"fetch_detail receives HTML containing the __UNIVERSAL_DATA_FOR_REHYDRATION__ script tag, but serde_json::from_str fails on its contents — e.g. TikTok returned an anti-bot page, a partially-rendered SSR page, or an encoding that breaks JSON parsing.","commonSituations":"TikTok's bot protection serving a challenge page instead of the real video page; TikTok changing the payload shape/escaping; proxy or CDN mangling the response; rate-limiting from rapid repeated get_media_info calls.","solutions":["Wait a few minutes and retry — TikTok is likely serving an anti-bot challenge (see the companion 'TikTok is blocking requests' error).","Check that the URL is a canonical tiktok.com video URL (@user/video/id) rather than a share/redirect link.","Retry through a different IP / proxy or with fresh cookies to avoid the challenge page.","Fall back to the yt-dlp path (get_media_info_via_ytdlp), which does not depend on the rehydration JSON."],"exampleFix":"// caller-side fallback\nmatch tiktok.get_media_info(url).await {\n    Ok(info) => info,\n    Err(e) if e.to_string().contains(\"Erro ao processar resposta do TikTok\") => {\n        tiktok.get_media_info_via_ytdlp(url, &post_id).await?\n    }\n    Err(e) => return Err(e),\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"match tiktok.get_media_info(url).await {\n    Err(e) if e.to_string().contains(\"Erro ao processar resposta do TikTok\") => tiktok.get_media_info_via_ytdlp(url, &post_id).await,\n    other => other,\n}","preventionTips":["Always implement the yt-dlp fallback alongside the direct scraper.","Back off between requests to avoid triggering TikTok's anti-bot challenge pages.","Send realistic browser headers/cookies with every request.","Monitor for this error spike as a signal that TikTok changed its response format."],"tags":["tiktok","json-parse","scraping","anti-bot"],"backgroundTag":"json-parse-error","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"}