From dd0a64aff0e13645ec7e8fffaaee622aa760b132 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sun, 26 Feb 2023 12:51:19 -0500 Subject: [PATCH] Added try catch to catch errors from parsing rss --- libCore.js | 60 +++++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/libCore.js b/libCore.js index 7852e07..e1c6728 100644 --- a/libCore.js +++ b/libCore.js @@ -89,39 +89,43 @@ exports.updateFeeds = async (client) => { log.ERROR("Parser Error: ", source.link, err); //return; } + + try{ + log.DEBUG("Parsed Feed Keys", Object.keys(parsedFeed), parsedFeed?.title); - log.DEBUG("Parsed Feed Keys", Object.keys(parsedFeed), parsedFeed?.title); - - if (parsedFeed?.items){ - for (const post of parsedFeed.items){ - log.VERBOSE("Post from feed: ", post); - if (post.title && post.link && post.content && ( post.postId || post.guid || post.id ) && post.pubDate){ - post.postId = post.postId ?? post.guid ?? post.id; - postStorage.getRecordBy('post_guid', post.postId, (err, existingRecord) => { - if (err) throw err; - log.DEBUG("Existing post record: ", existingRecord); - if (!existingRecord){ - const channel = client.channels.cache.get(source.channel_id); - libUtils.sendPost(post, channel, (err, sendResults) =>{ - if (err) throw err; + if (parsedFeed?.items){ + for (const post of parsedFeed.items){ + log.VERBOSE("Post from feed: ", post); + if (post.title && post.link && post.content && ( post.postId || post.guid || post.id ) && post.pubDate){ + post.postId = post.postId ?? post.guid ?? post.id; + postStorage.getRecordBy('post_guid', post.postId, (err, existingRecord) => { + if (err) throw err; + log.DEBUG("Existing post record: ", existingRecord); + if (!existingRecord){ + const channel = client.channels.cache.get(source.channel_id); + libUtils.sendPost(post, channel, (err, sendResults) =>{ + if (err) throw err; - if (sendResults){ - log.DEBUG("Saving post to database: ", sendResults, post.title, source.channel_id); + if (sendResults){ + log.DEBUG("Saving post to database: ", sendResults, post.title, source.channel_id); - postStorage.savePost(post, (err, saveResults) => { - if(err) throw err; + postStorage.savePost(post, (err, saveResults) => { + if(err) throw err; - if (saveResults) { - log.DEBUG("Saved results: ", saveResults); - } - }); - } - }) - } - }) + if (saveResults) { + log.DEBUG("Saved results: ", saveResults); + } + }); + } + }) + } + }) + } } - } - } + } + }catch (err) { + log.ERROR("Error Parsing Feed: ", source.link, err); + } }); } });