{"record":{"id":"dbec8be7eee95293","repo":"RayWangQvQ/BiliBiliToolPro","slug":"re-message","errorCode":null,"errorMessage":"re.Message","messagePattern":"re\\.Message","errorType":"exception","errorClass":"BiliBusinessException","httpStatus":null,"severity":"error","filePath":"src/Ray.BiliBiliTool.DomainService/ArticleDomainService.cs","lineNumber":172,"sourceCode":"        if (articleCount == 0)\n        {\n            return 0;\n        }\n\n        var req = new SearchArticlesByUpIdDto()\n        {\n            mid = mid,\n            ps = 1,\n            pn = new Random().Next(1, articleCount + 1),\n        };\n\n        BiliApiResponse<SearchUpArticlesResponse> re = await apiApi.SearchUpArticlesByUpIdAsync(\n            req\n        );\n\n        if (re.Code != 0)\n        {\n            throw new BiliBusinessException(re.Message);\n        }\n\n        var articleInfo = re.Data.Articles.FirstOrDefault();\n\n        logger.LogInformation(\"获取到的专栏{cvid}({title})\", articleInfo?.Id, articleInfo?.Title);\n\n        // 检查是否可投\n        if (articleInfo == null || !await IsCanDonate(articleInfo.Id))\n        {\n            return 0;\n        }\n\n        return articleInfo.Id;\n    }\n\n    // TODO 转变为异步代码\n    /// <summary>\n    /// 从支持UP主列表中随机挑选一位","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/RayWangQvQ/BiliBiliToolPro/blob/c599b2c0da964e16ea8c454397aa07bb16212628/src/Ray.BiliBiliTool.DomainService/ArticleDomainService.cs#L154-L190","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the exception message — it is the raw Bili API message — and address the indicated cause (usually re-auth with a fresh cookie).","Verify the target up actually has published articles before invoking this flow.","Add pacing/backoff to reduce risk-control and rate-limit responses.","Update to the latest library version if Bili changed the search API contract."],"exampleFix":"// before\nvar article = await articleDomainService.GetRandomArticleFromUp(upId, cookie);\n// after (guard with try-catch and fallback)\ntry { var article = await articleDomainService.GetRandomArticleFromUp(upId, cookie); }\ncatch (BiliBusinessException ex) { logger.LogWarning(\"文章搜索失败: {0}\", ex.Message); /* fallback */ }","handlingStrategy":"try-catch","validationCode":"// ensure cookie is valid and the up has articles before the call\nif (string.IsNullOrWhiteSpace(upId)) throw new ArgumentException(\"upId is required\");","typeGuard":null,"tryCatchPattern":"try { var article = await svc.GetRandomArticleFromUp(req); }\ncatch (BiliBusinessException ex)\n{\n    logger.LogWarning(\"Bili API 返回错误: {Msg}\", ex.Message);\n    // apply fallback: skip article task or retry later\n}","preventionTips":["Throttle automated requests to avoid risk-control errors.","Keep the library updated for Bili API changes.","Confirm the target up has published articles."],"tags":["csharp","api","bili","error-response"],"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"}