From 90c4c7ea4d4fddc39c800d3a979a170270b99d8d Mon Sep 17 00:00:00 2001 From: JimenezLi <75196426+JimenezLi@users.noreply.github.com> Date: Fri, 11 Aug 2023 20:48:04 +0800 Subject: [PATCH] fix(route): `/bilibili/user/video(article)` Broken for some uploaders (#12992) * Fix /bilibili/user/video Error message: Cannot read properties of undefined (reading 'name') * /bilibili/user/video returns error message if fail to fetch --- lib/v2/bilibili/cache.js | 8 +++++--- lib/v2/bilibili/video.js | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/v2/bilibili/cache.js b/lib/v2/bilibili/cache.js index 1b2d6bf99..5dd05ea71 100644 --- a/lib/v2/bilibili/cache.js +++ b/lib/v2/bilibili/cache.js @@ -71,7 +71,7 @@ module.exports = { Cookie: cookie, }, }); - return nameResponse.data.name; + return nameResponse.data ? nameResponse.data.name : undefined; }); }, getUsernameAndFaceFromUID: async (ctx, uid) => { @@ -95,8 +95,10 @@ module.exports = { Cookie: cookie, }, }); - name = nameResponse.data.name; - face = nameResponse.data.face; + if (nameResponse.data) { + name = nameResponse.data.name; + face = nameResponse.data.face; + } ctx.cache.set(nameKey, name); ctx.cache.set(faceKey, face); } diff --git a/lib/v2/bilibili/video.js b/lib/v2/bilibili/video.js index ef6aeb18d..c31aadcd4 100644 --- a/lib/v2/bilibili/video.js +++ b/lib/v2/bilibili/video.js @@ -23,6 +23,9 @@ module.exports = async (ctx) => { }, }); const data = response.data; + if (data.code) { + throw new Error(`Got error code ${data.code} while fetching: ${data.message}`); + } ctx.state.data = { title: `${name} 的 bilibili 空间`,