From c276eb9661f57ff9138de9f10f764f33d4b80418 Mon Sep 17 00:00:00 2001 From: Goestav <27970303+goestav@users.noreply.github.com> Date: Mon, 19 May 2025 14:14:41 +0000 Subject: [PATCH] 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 --- lib/routes/kurogames/wutheringwaves/constants.ts | 2 +- lib/routes/kurogames/wutheringwaves/news.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/routes/kurogames/wutheringwaves/constants.ts b/lib/routes/kurogames/wutheringwaves/constants.ts index 9d0ae687c..63efc6502 100644 --- a/lib/routes/kurogames/wutheringwaves/constants.ts +++ b/lib/routes/kurogames/wutheringwaves/constants.ts @@ -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; diff --git a/lib/routes/kurogames/wutheringwaves/news.ts b/lib/routes/kurogames/wutheringwaves/news.ts index fff5216d6..0a734a6d7 100644 --- a/lib/routes/kurogames/wutheringwaves/news.ts +++ b/lib/routes/kurogames/wutheringwaves/news.ts @@ -63,7 +63,10 @@ Language codes for the \`${Parameter.Language}\` parameter: }; return cache.tryGet(`wutheringwaves:${language}:${article.articleId}`, async () => { - const { articleContent } = await ofetch
(contentUrl, { query: { t: Date.now() } }); + const articleDetails = await ofetch
(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 ?? '';