fix(route): line today ignore 404 (#12779)
This commit is contained in:
+18
-2
@@ -1,7 +1,7 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const logger = require('@/utils/logger');
|
||||
const baseUrl = 'https://today.line.me';
|
||||
|
||||
const parseList = (items) =>
|
||||
@@ -18,7 +18,23 @@ const parseItems = (list, tryGet) =>
|
||||
list.map((item) =>
|
||||
tryGet(item.link, async () => {
|
||||
const edition = item.link.match(/today\.line\.me\/(\w+?)\/v2\/.*$/)[1];
|
||||
const { data } = await got(`${baseUrl}/webapi/portal/page/setting/article?country=${edition}&hash=${item.hash}&group=NA`);
|
||||
let data;
|
||||
try {
|
||||
const response = await got(`${baseUrl}/webapi/portal/page/setting/article`, {
|
||||
searchParams: {
|
||||
country: edition,
|
||||
hash: item.hash,
|
||||
group: 'NA',
|
||||
},
|
||||
});
|
||||
data = response.data;
|
||||
} catch (error) {
|
||||
if (error instanceof got.HTTPError && error.response.statusCode === 404) {
|
||||
logger.error(`Error parsing article ${item.link}: ${error.message}`);
|
||||
return item;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
const $ = cheerio.load(data.data.content, null, false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user