RayWangQvQ/BiliBiliToolPro · error · BiliBusinessException
liveHomeContent?.Message ?? "Live API returned failure"
Error message
liveHomeContent?.Message ?? "Live API returned failure"
What it means
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.
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.
Defensive patterns
Strategy: validation
Validate before calling
// before running live/fans-medal tasks, sanity-check the cookie
if (string.IsNullOrEmpty(ck.Sessdata) || string.IsNullOrEmpty(ck.BiliJct))
throw new Exception("Cookie 缺少 SESSDATA 或 bili_jct,请重新导出"); Type guard
bool IsValidLiveCookie(BiliCookie? ck) => ck is not null && !string.IsNullOrEmpty(ck.Sessdata) && !string.IsNullOrEmpty(ck.BiliJct);
Try / catch
try
{
await CheckLiveCookie(ck);
}
catch (BiliBusinessException ex)
{
logger.LogError("直播Cookie校验失败:{msg}", ex.Message);
throw; // cookie problems need human intervention
} Prevention
- 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.
When it happens
Trigger: liveApi.GetLiveHome returns Code != 0 (expired/banned cookie, missing live-related cookie fields), or the response body fails JSON deserialization so liveHomeContent is null.
Common situations: 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.
Related errors
AI-assisted analysis of RayWangQvQ/BiliBiliToolPro@c599b2c0da (2026-09-12).
Data as JSON: /api/errors/1bac99dbd677f06a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Ray.BiliBiliTool.DomainService/LiveDomainService.cs:731
/// </returns>
private async Task<bool> CheckLiveCookie(BiliCookie ck)
{
// 检测 _biliCookie 是否正确配置
if (!string.IsNullOrWhiteSpace(ck.LiveBuvid))
return true;
try
{
logger.LogInformation("检测到直播 Cookie 未正确配置,尝试自动配置中...");
// 请求主播主页来正确配置 cookie
var liveHome = await liveApi.GetLiveHome(ck.ToString());
var liveHomeContent = JsonConvert.DeserializeObject<BiliApiResponse>(
await liveHome.Content.ReadAsStringAsync()
);
if (liveHomeContent?.Code != 0)
{
throw new BiliBusinessException(
liveHomeContent?.Message ?? "Live API returned failure"
);
}
var setHeader = liveHome.Headers.FirstOrDefault(header => header.Key == "Set-Cookie");
ck.MergeCurrentCookie(setHeader.Value.ToList());
logger.LogDebug("LiveBuvid {value}", ck.LiveBuvid);
logger.LogInformation("直播 Cookie 配置成功!");
}
catch (Exception exception)
{
logger.LogError("【配置直播Cookie】失败,放弃执行后续任务...");
logger.LogError("【原因】{message}", exception.Message);
return false;
}
return true;View on GitHub (pinned to c599b2c0da)