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:
parent
4aaeb2713d
commit
c276eb9661
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 ?? '';
|
||||
|
|
|
|||
Loading…
Reference in New Issue