Skip to content

Commit

Permalink
feat: catch invalid URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
Candinya committed Apr 13, 2022
1 parent cbe7872 commit cd6c5c5
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions scripts/friends.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,18 @@ hexo.once('generateAfter', () => {

const https = require('https');
friends.list.forEach((friend) => {
https.get(friend.link)
.on('error', err => {
hexo.log.warn(`友链"${friend.name}"(${friend.link})出现错误,以下是错误信息:`);
hexo.log.warn(err);
});

try {
// 尝试请求 URL
https.get(friend.link)
.on('error', err => {
hexo.log.warn(`友链"${friend.name}"(${friend.link})出现错误,以下是错误信息:`);
hexo.log.warn(err);
});
} catch (e) {
// 如果出现问题(例如无效的 URL ),给出提示
hexo.log.warn(`友链"${friend.name}"(${friend.link})无法被请求,以下是错误信息:`);
hexo.log.warn(e);
}
});
});

0 comments on commit cd6c5c5

Please sign in to comment.