{"record":{"id":"6a00ac9fc58f2a09","repo":"Kuberwastaken/claurst","slug":"exchange-code-bad-json","errorCode":null,"errorMessage":"exchange_code: bad JSON: {}","messagePattern":"exchange_code: bad JSON: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-rust/crates/mcp/src/oauth.rs","lineNumber":502,"sourceCode":"        .send()\n        .await\n        .map_err(|e| anyhow::anyhow!(\"exchange_code: request failed: {}\", e))?;\n\n    if !resp.status().is_success() {\n        let status = resp.status();\n        let body = resp.text().await.unwrap_or_default();\n        anyhow::bail!(\"exchange_code: HTTP {} — {}\", status, body);\n    }\n\n    #[derive(serde::Deserialize)]\n    struct TokenResponse {\n        access_token: String,\n        refresh_token: Option<String>,\n        expires_in: Option<u64>,\n        scope: Option<String>,\n    }\n\n    let tr: TokenResponse = resp.json().await.map_err(|e| anyhow::anyhow!(\"exchange_code: bad JSON: {}\", e))?;\n\n    let expires_at = tr.expires_in.map(|secs| {\n        std::time::SystemTime::now()\n            .duration_since(std::time::UNIX_EPOCH)\n            .unwrap_or_default()\n            .as_secs()\n            + secs\n    });\n\n    Ok(McpToken {\n        access_token: tr.access_token,\n        refresh_token: tr.refresh_token,\n        expires_at,\n        scope: tr.scope,\n        server_name: String::new(), // caller should set this\n    })\n}\n","sourceCodeStart":484,"sourceCodeEnd":520,"githubUrl":"https://github.com/Kuberwastaken/claurst/blob/b0637c97ec34144387cbf2f74f65df6d16a6cef1/src-rust/crates/mcp/src/oauth.rs#L484-L520","documentation":"The token endpoint returned HTTP success but the response body was not valid JSON matching the expected TokenResponse shape (missing required access_token field, malformed JSON, or an HTML error page with a 200 status). The grant itself may have half-succeeded; the token cannot be deserialized.","triggerScenarios":"Thrown at src-rust/crates/mcp/src/oauth.rs:502 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the raw token endpoint response body (capture via logging/proxy) to see what was returned","Verify the server implements RFC 6749 token responses with an access_token field","Retry the flow; some servers intermittently return HTML error pages"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b0637c97ec34144387cbf2f74f65df6d16a6cef1","analyzedAt":"2026-09-10T00:24:58.650Z","contentChangedAt":"2026-09-10T00:24:58.650Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}