Skip to content

Commit

Permalink
fix(route/bilibili): add logger to handle error codes (DIYgod#16721)
Browse files Browse the repository at this point in the history
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 DIYgod#16716
  • Loading branch information
Konano authored Sep 12, 2024
1 parent dbc1628 commit ffb4767
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/routes/bilibili/followings-video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?',
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ffb4767

Please sign in to comment.