From 27e3489fb68d57bab1468b55a7475498a3c5bb8a Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 19 Dec 2020 00:30:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9C=AC=E5=9C=B0=E5=AE=9D=E4=B8=A2?= =?UTF-8?q?=E5=BC=83=E8=BF=87=E6=9C=9F=E9=93=BE=E6=8E=A5=20(#6472)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/bendibao/news.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/routes/bendibao/news.js b/lib/routes/bendibao/news.js index 9c91c2372..5addbd411 100644 --- a/lib/routes/bendibao/news.js +++ b/lib/routes/bendibao/news.js @@ -55,25 +55,30 @@ module.exports = async (ctx) => { list.map( async (item) => await ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ method: 'get', url: item.link }); - const content = cheerio.load(detailResponse.data); + try { + const detailResponse = await got({ method: 'get', url: item.link }); + const content = cheerio.load(detailResponse.data); - // Some links lead to mobile-view pages. - // eg. http://m.bj.bendibao.com/news/273517.html - // Divs for contents are different from which in desktop-view pages. + // Some links lead to mobile-view pages. + // eg. http://m.bj.bendibao.com/news/273517.html + // Divs for contents are different from which in desktop-view pages. - item.description = content('div.content').html() ? content('div.content').html() : content('div.content-box').html(); + item.description = content('div.content').html() || content('div.content-box').html(); - // Spans for publish dates are the same cases as above. + // Spans for publish dates are the same cases as above. - item.pubDate = new Date((content('span.time').text() ? content('span.time').text().replace(/发布时间:/, '') : content('span.public_time').text()) + ' GMT+8').toUTCString(); - return item; + item.pubDate = new Date((content('span.time').text().replace(/发布时间:/, '') || content('span.public_time').text()) + ' GMT+8').toUTCString(); + + return item; + } catch (e) { + return Promise.resolve(''); + } }) ) ); ctx.state.data = { - title: title, + title, link: `http://${city}.bendibao.com/`, item: items, };