{"record":{"id":"e2f5803eb1c8bb9c","repo":"RayWangQvQ/BiliBiliToolPro","slug":"re-message-videodomainservice","errorCode":null,"errorMessage":"re.Message","messagePattern":"re\\.Message","errorType":"exception","errorClass":"BiliBusinessException","httpStatus":null,"severity":"error","filePath":"src/Ray.BiliBiliTool.DomainService/VideoDomainService.cs","lineNumber":70,"sourceCode":"    {\n        if (total <= 0)\n            return null;\n\n        var req = new SearchVideosByUpIdDto()\n        {\n            mid = upId,\n            ps = 1,\n            pn = new Random().Next(1, total + 1),\n        };\n\n        BiliApiResponse<SearchUpVideosResponse> re = await apiApi.SearchVideosByUpId(\n            req,\n            ck.ToString()\n        );\n\n        if (re.Code != 0)\n        {\n            throw new BiliBusinessException(re.Message);\n        }\n\n        return re.Data?.List?.Vlist.FirstOrDefault();\n    }\n\n    /// <summary>\n    /// 获取UP主的视频总数量\n    /// </summary>\n    /// <param name=\"upId\"></param>\n    /// <returns></returns>\n    public async Task<int> GetVideoCountOfUp(long upId, BiliCookie ck)\n    {\n        var req = new SearchVideosByUpIdDto() { mid = upId };\n\n        BiliApiResponse<SearchUpVideosResponse> re = await apiApi.SearchVideosByUpId(\n            req,\n            ck.ToString()\n        );","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/RayWangQvQ/BiliBiliToolPro/blob/c599b2c0da964e16ea8c454397aa07bb16212628/src/Ray.BiliBiliTool.DomainService/VideoDomainService.cs#L52-L88","documentation":"Thrown by GetRandomVideoOfUp when the Bilibili search-by-up-id API returns a non-zero code. Any failure listing an UP主's videos (private/banned account, API rejection, risk control) is surfaced directly to the caller as BiliBusinessException(re.Message).","triggerScenarios":"apiApi.SearchVideosByUpId responds with re.Code != 0 — the UP id doesn't exist or the account is closed/hidden, the pn page number (random) exceeds available pages and Bilibili rejects it, cookie invalid, or risk-control code returned.","commonSituations":"Target UP主 deleted/privated all videos so the search API errors; the random page number computed from a stale total exceeds the current page count; cookie expired; Bilibili search API changed behavior.","solutions":["Check re.Message to identify the specific Bilibili error code.","Verify the UP id (mid) exists and the account still has public videos.","Recompute the video total (GetVideoCountOfUp) before picking a random page so pn stays in range.","Refresh the Bilibili cookie if the message indicates authentication failure."],"exampleFix":"// before: random page from possibly stale total\npn = new Random().Next(1, total + 1),\n// after: refresh total and clamp\nvar total = await GetVideoCountOfUp(upId, ck);\nif (total <= 0) return null;\npn = new Random().Next(1, total + 1)","handlingStrategy":"try-catch","validationCode":"// ensure the UP has videos and total is fresh before picking a random page\nvar total = await videoDomainService.GetVideoCountOfUp(upId, ck);\nif (total <= 0)\n    return; // skip this UP, no videos to interact with","typeGuard":"bool CanInteractWithUp(long upId, int total) => upId > 0 && total > 0;","tryCatchPattern":"try\n{\n    var video = await videoDomainService.GetRandomVideoOfUp(upId, total, ck);\n}\ncatch (BiliBusinessException ex)\n{\n    logger.LogWarning(\"获取UP主({upId})视频失败，跳过：{msg}\", upId, ex.Message);\n}","preventionTips":["Refresh the UP's video count before generating a random page number.","Validate the UP id/mid exists and is public.","Keep the cookie fresh to avoid auth-related non-zero codes."],"tags":["bilibili-api","video-search","business-exception"],"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"}