From ffb4767dacd8528a70a98553c32771fda31cd490 Mon Sep 17 00:00:00 2001 From: Nano Date: Thu, 12 Sep 2024 21:44:59 +0800 Subject: [PATCH] fix(route/bilibili): add logger to handle error codes (#16721) Add logger to handle error codes returned by the Bilibili API. If the response code is -6 or 4100000, it throws a ConfigNotFoundError. Otherwise, it throws an error with the corresponding error code and message. Fixes #16716 --- lib/routes/bilibili/followings-video.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/routes/bilibili/followings-video.ts b/lib/routes/bilibili/followings-video.ts index 6a112ed90..0707a2402 100644 --- a/lib/routes/bilibili/followings-video.ts +++ b/lib/routes/bilibili/followings-video.ts @@ -4,6 +4,7 @@ import cache from './cache'; import { config } from '@/config'; import utils from './utils'; import ConfigNotFoundError from '@/errors/types/config-not-found'; +import logger from '@/utils/logger'; export const route: Route = { path: '/followings/video/:uid/:disableEmbed?', @@ -53,10 +54,15 @@ async function handler(ctx) { Cookie: cookie, }, }); - if (response.data.code === -6) { - throw new ConfigNotFoundError('对应 uid 的 Bilibili 用户的 Cookie 已过期'); + const data = response.data; + if (data.code) { + logger.error(JSON.stringify(data)); + if (data.code === -6 || data.code === 4_100_000) { + throw new ConfigNotFoundError('对应 uid 的 Bilibili 用户的 Cookie 已过期'); + } + throw new Error(`Got error code ${data.code} while fetching: ${data.message}`); } - const cards = response.data.data.cards; + const cards = data.data.cards; const out = cards.map((card) => { const card_data = JSON.parse(card.card);