fix(route/kurogames): handle unavailable article content property (#19131)

The article https://wutheringwaves.kurogames.com/zh-tw/main/news/detail/2596 has no article content
property in the API and causes a cheerio load error during runtime, this commit fixes that issue and
falls back to an empty RSS item description for these kind of articles.

Closes #19124
This commit is contained in:
Goestav 2025-05-19 14:14:41 +00:00 committed by GitHub
parent 4aaeb2713d
commit c276eb9661
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 2 deletions

View File

@ -21,7 +21,7 @@ export enum Parameter {
export const SUPPORTED_LANGUAGES = Object.values(Language);
export interface Article {
articleContent: string;
articleContent?: string;
articleDesc: string;
articleId: number;
articleTitle: string;

View File

@ -63,7 +63,10 @@ Language codes for the \`${Parameter.Language}\` parameter:
};
return cache.tryGet(`wutheringwaves:${language}:${article.articleId}`, async () => {
const { articleContent } = await ofetch<Article>(contentUrl, { query: { t: Date.now() } });
const articleDetails = await ofetch<Article>(contentUrl, { query: { t: Date.now() } });
// Article content may not always be available, e.g: https://wutheringwaves.kurogames.com/zh-tw/main/news/detail/2596
const articleContent = articleDetails.articleContent ?? '';
const $ = cheerio.load(articleContent);
item.description = $.html() ?? article.articleDesc ?? '';