{"record":{"id":"1bac99dbd677f06a","repo":"RayWangQvQ/BiliBiliToolPro","slug":"livehomecontent-message-live-api-returned-failure","errorCode":null,"errorMessage":"liveHomeContent?.Message ?? \"Live API returned failure\"","messagePattern":"liveHomeContent\\?\\.Message \\?\\? \"Live API returned failure\"","errorType":"exception","errorClass":"BiliBusinessException","httpStatus":null,"severity":"error","filePath":"src/Ray.BiliBiliTool.DomainService/LiveDomainService.cs","lineNumber":731,"sourceCode":"    /// </returns>\n    private async Task<bool> CheckLiveCookie(BiliCookie ck)\n    {\n        // 检测 _biliCookie 是否正确配置\n        if (!string.IsNullOrWhiteSpace(ck.LiveBuvid))\n            return true;\n\n        try\n        {\n            logger.LogInformation(\"检测到直播 Cookie 未正确配置，尝试自动配置中...\");\n\n            // 请求主播主页来正确配置 cookie\n            var liveHome = await liveApi.GetLiveHome(ck.ToString());\n            var liveHomeContent = JsonConvert.DeserializeObject<BiliApiResponse>(\n                await liveHome.Content.ReadAsStringAsync()\n            );\n            if (liveHomeContent?.Code != 0)\n            {\n                throw new BiliBusinessException(\n                    liveHomeContent?.Message ?? \"Live API returned failure\"\n                );\n            }\n\n            var setHeader = liveHome.Headers.FirstOrDefault(header => header.Key == \"Set-Cookie\");\n            ck.MergeCurrentCookie(setHeader.Value.ToList());\n\n            logger.LogDebug(\"LiveBuvid {value}\", ck.LiveBuvid);\n            logger.LogInformation(\"直播 Cookie 配置成功！\");\n        }\n        catch (Exception exception)\n        {\n            logger.LogError(\"【配置直播Cookie】失败，放弃执行后续任务...\");\n            logger.LogError(\"【原因】{message}\", exception.Message);\n            return false;\n        }\n\n        return true;","sourceCodeStart":713,"sourceCodeEnd":749,"githubUrl":"https://github.com/RayWangQvQ/BiliBiliToolPro/blob/c599b2c0da964e16ea8c454397aa07bb16212628/src/Ray.BiliBiliTool.DomainService/LiveDomainService.cs#L713-L749","documentation":"Thrown by CheckLiveCookie when the Bilibili live-home API response cannot be parsed or reports a non-zero code. It validates the live cookie: it fetches the live home page, deserializes the JSON envelope, and if Code != 0 (or the body failed to deserialize, leaving liveHomeContent null) it throws BiliBusinessException carrying the API message. This means the cookie used for live/fans-medal tasks is invalid or the live API is failing.","triggerScenarios":"liveApi.GetLiveHome returns Code != 0 (expired/banned cookie, missing live-related cookie fields), or the response body fails JSON deserialization so liveHomeContent is null.","commonSituations":"Cookie expired or partially copied (missing SESSDATA/bili_jct); account restricted from live features; Bilibili live API changed response shape causing deserialization failure; network/proxy returning an HTML error page instead of JSON.","solutions":["Re-export a fresh Bilibili cookie (SESSDATA, bili_jct, DedeUserID) and update the config/environment variable.","Manually curl the live home API with the cookie to see the raw code/message returned.","Ensure the HTTP response is actually JSON — check whether a proxy or login redirect returns HTML.","Update the library in case the live API response schema changed."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before running live/fans-medal tasks, sanity-check the cookie\nif (string.IsNullOrEmpty(ck.Sessdata) || string.IsNullOrEmpty(ck.BiliJct))\n    throw new Exception(\"Cookie 缺少 SESSDATA 或 bili_jct，请重新导出\");","typeGuard":"bool IsValidLiveCookie(BiliCookie? ck) => ck is not null && !string.IsNullOrEmpty(ck.Sessdata) && !string.IsNullOrEmpty(ck.BiliJct);","tryCatchPattern":"try\n{\n    await CheckLiveCookie(ck);\n}\ncatch (BiliBusinessException ex)\n{\n    logger.LogError(\"直播Cookie校验失败：{msg}\", ex.Message);\n    throw; // cookie problems need human intervention\n}","preventionTips":["Re-export the full cookie regularly; SESSDATA expires.","Include SESSDATA, bili_jct and DedeUserID when copying cookies.","Test the live API manually with curl when the cookie is first configured."],"tags":["bilibili-live","cookie-validation","api-error-response","json-deserialization"],"backgroundTag":"api-error-response","analyzedSha":"c599b2c0da964e16ea8c454397aa07bb16212628","analyzedAt":"2026-09-12T09:48:04.090Z","contentChangedAt":"2026-09-12T09:48:04.090Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}