{"record":{"id":"b6986a57134e3f53","repo":"tonhowtf/omniget","slug":"o-trakt-recusou-o-pedido-de-c-digo-http-confira-o-client-id","errorCode":null,"errorMessage":"o Trakt recusou o pedido de código (HTTP {}) — confira o client_id","messagePattern":"o Trakt recusou o pedido de código \\(HTTP (.+?)\\) — confira o client_id","errorType":"exception","errorClass":"anyhow","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/lists/trakt.rs","lineNumber":246,"sourceCode":"/// Passo 1: pede o código que o usuário vai digitar em trakt.tv/activate.\npub async fn device_code() -> Result<DeviceCode> {\n    let c = {\n        let _g = LOCK.lock().unwrap_or_else(|e| e.into_inner());\n        load()\n    };\n    if c.client_id.is_empty() {\n        return Err(anyhow!(\n            \"informe primeiro o client_id da sua app do Trakt (crie em {})\",\n            APP_URL\n        ));\n    }\n    let r = client()?\n        .post(format!(\"{}/oauth/device/code\", AUTH))\n        .json(&serde_json::json!({ \"client_id\": c.client_id }))\n        .send()\n        .await?;\n    if !r.status().is_success() {\n        return Err(anyhow!(\n            \"o Trakt recusou o pedido de código (HTTP {}) — confira o client_id\",\n            r.status()\n        ));\n    }\n    let v: Value = r.json().await?;\n    parse_device_code(&v)\n}\n\npub fn parse_device_code(v: &Value) -> Result<DeviceCode> {\n    let s = |k: &str| {\n        v.get(k)\n            .and_then(|x| x.as_str())\n            .unwrap_or_default()\n            .to_string()\n    };\n    let n = |k: &str, d: u64| v.get(k).and_then(|x| x.as_u64()).unwrap_or(d);\n    let device = s(\"device_code\");\n    let user = s(\"user_code\");","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/lists/trakt.rs#L228-L264","documentation":"Thrown by device_code() when the POST to https://api.trakt.tv/oauth/device/code returns a non-2xx status. Trakt rejected the code request, almost always because the supplied client_id is invalid, mistyped, or belongs to a deleted app.","triggerScenarios":"POST /oauth/device/code with a client_id that Trakt does not recognize — wrong value, extra whitespace, revoked/deleted app, or malformed config data.","commonSituations":"Copy-paste errors (trailing spaces, truncation), using the client_secret in the client_id field, deleting the Trakt app and recreating it (new credentials), typos in the config file.","solutions":["Check the HTTP status in the message: 401/400 usually means bad client_id","Re-copy the client_id from https://trakt.tv/oauth/applications and save it in the config","Confirm the app still exists and is not deleted/revoked on Trakt","Retry device_code() after fixing the credentials"],"exampleFix":"// before\nconfig.client_id = \"  <id with trailing space> \";\n// after\nconfig.client_id = config.client_id.trim();\nsave(config);","handlingStrategy":"try-catch","validationCode":"if config.client_id.len() < 20 || config.client_id.contains(char::is_whitespace) {\n    return Err(\"client_id parece inválido — copie novamente do Trakt\".into());\n}","typeGuard":null,"tryCatchPattern":"match device_code().await {\n    Err(e) if e.to_string().contains(\"recusou o pedido\") => {\n        // prompt user to re-enter client_id\n    }\n    other => other?,\n}","preventionTips":["Trim credentials on save","Verify the app still exists on trakt.tv/oauth/applications after any Trakt account changes","Never swap client_id and client_secret fields"],"tags":["oauth","trakt","http","device-flow"],"backgroundTag":"api-error-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"}