mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-06 13:08:14 +08:00
fix: if fulltext parser failed, return default description and… (#2992)
This commit is contained in:
@@ -19,16 +19,21 @@ module.exports = async (ctx, next) => {
|
||||
const tasks = ctx.state.data.item.map(async (item) => {
|
||||
const { link, author, description } = item;
|
||||
const parsed_result = await ctx.cache.tryGet(`mercury-cache-${link}`, async () => {
|
||||
const res = await got(link);
|
||||
const $ = cheerio.load(res.data);
|
||||
const result = await mercury_parser.parse(link, {
|
||||
html: $.html(),
|
||||
});
|
||||
return result;
|
||||
// if parser failed, return default description and not report error
|
||||
try {
|
||||
const res = await got(link);
|
||||
const $ = cheerio.load(res.data);
|
||||
const result = await mercury_parser.parse(link, {
|
||||
html: $.html(),
|
||||
});
|
||||
return result;
|
||||
} catch (e) {
|
||||
// no-empty
|
||||
}
|
||||
});
|
||||
|
||||
item.author = author || parsed_result.author;
|
||||
item.description = parsed_result.content || description;
|
||||
item.author = author || (parsed_result ? parsed_result.author : '');
|
||||
item.description = parsed_result ? parsed_result.content : description;
|
||||
});
|
||||
await Promise.all(tasks);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user