RayWangQvQ/BiliBiliToolPro · error · BiliBusinessException

re.Message

Error message

re.Message

What it means

GetRandomArticleFromUp calls SearchUpArticlesByUpIdAsync and throws BiliBusinessException carrying the API's own message when the response Code != 0, surfacing Bili server-side failures (e.g. no results, risk control, auth issues) to the caller.

Solutions

  1. Read the exception message — it is the raw Bili API message — and address the indicated cause (usually re-auth with a fresh cookie).
  2. Verify the target up actually has published articles before invoking this flow.
  3. Add pacing/backoff to reduce risk-control and rate-limit responses.
  4. Update to the latest library version if Bili changed the search API contract.

Example fix

// before
var article = await articleDomainService.GetRandomArticleFromUp(upId, cookie);
// after (guard with try-catch and fallback)
try { var article = await articleDomainService.GetRandomArticleFromUp(upId, cookie); }
catch (BiliBusinessException ex) { logger.LogWarning("文章搜索失败: {0}", ex.Message); /* fallback */ }
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure cookie is valid and the up has articles before the call
if (string.IsNullOrWhiteSpace(upId)) throw new ArgumentException("upId is required");

Try / catch

try { var article = await svc.GetRandomArticleFromUp(req); }
catch (BiliBusinessException ex)
{
    logger.LogWarning("Bili API 返回错误: {Msg}", ex.Message);
    // apply fallback: skip article task or retry later
}

Prevention

When it happens

Trigger: Any call where the search-up-articles API returns a non-zero code: invalid/insufficient cookie privileges, Bili risk control, target up has no visible articles, or transient Bili API errors.

Common situations: Running without valid login for endpoints that require it; requesting articles of an up whose article list is empty or hidden; Bili API changes/deprecations; heavy automated usage triggering rate limits.

Related errors


AI-assisted analysis of RayWangQvQ/BiliBiliToolPro@c599b2c0da (2026-09-12). Data as JSON: /api/errors/dbec8be7eee95293. Report an issue: GitHub.

Appendix: source

Thrown at src/Ray.BiliBiliTool.DomainService/ArticleDomainService.cs:172

        if (articleCount == 0)
        {
            return 0;
        }

        var req = new SearchArticlesByUpIdDto()
        {
            mid = mid,
            ps = 1,
            pn = new Random().Next(1, articleCount + 1),
        };

        BiliApiResponse<SearchUpArticlesResponse> re = await apiApi.SearchUpArticlesByUpIdAsync(
            req
        );

        if (re.Code != 0)
        {
            throw new BiliBusinessException(re.Message);
        }

        var articleInfo = re.Data.Articles.FirstOrDefault();

        logger.LogInformation("获取到的专栏{cvid}({title})", articleInfo?.Id, articleInfo?.Title);

        // 检查是否可投
        if (articleInfo == null || !await IsCanDonate(articleInfo.Id))
        {
            return 0;
        }

        return articleInfo.Id;
    }

    // TODO 转变为异步代码
    /// <summary>
    /// 从支持UP主列表中随机挑选一位

View on GitHub (pinned to c599b2c0da)