Added try catch to catch errors from parsing rss

This commit is contained in:
Logan Cusano
2023-02-26 12:51:19 -05:00
parent a9bc2383ba
commit dd0a64aff0

View File

@@ -89,39 +89,43 @@ exports.updateFeeds = async (client) => {
log.ERROR("Parser Error: ", source.link, err); log.ERROR("Parser Error: ", source.link, err);
//return; //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){
if (parsedFeed?.items){ log.VERBOSE("Post from feed: ", post);
for (const post of parsedFeed.items){ if (post.title && post.link && post.content && ( post.postId || post.guid || post.id ) && post.pubDate){
log.VERBOSE("Post from feed: ", post); post.postId = post.postId ?? post.guid ?? post.id;
if (post.title && post.link && post.content && ( post.postId || post.guid || post.id ) && post.pubDate){ postStorage.getRecordBy('post_guid', post.postId, (err, existingRecord) => {
post.postId = post.postId ?? post.guid ?? post.id; if (err) throw err;
postStorage.getRecordBy('post_guid', post.postId, (err, existingRecord) => { log.DEBUG("Existing post record: ", existingRecord);
if (err) throw err; if (!existingRecord){
log.DEBUG("Existing post record: ", existingRecord); const channel = client.channels.cache.get(source.channel_id);
if (!existingRecord){ libUtils.sendPost(post, channel, (err, sendResults) =>{
const channel = client.channels.cache.get(source.channel_id); if (err) throw err;
libUtils.sendPost(post, channel, (err, sendResults) =>{
if (err) throw err;
if (sendResults){ if (sendResults){
log.DEBUG("Saving post to database: ", sendResults, post.title, source.channel_id); log.DEBUG("Saving post to database: ", sendResults, post.title, source.channel_id);
postStorage.savePost(post, (err, saveResults) => { postStorage.savePost(post, (err, saveResults) => {
if(err) throw err; if(err) throw err;
if (saveResults) { if (saveResults) {
log.DEBUG("Saved results: ", saveResults); log.DEBUG("Saved results: ", saveResults);
} }
}); });
} }
}) })
} }
}) })
}
} }
} }
} }catch (err) {
log.ERROR("Error Parsing Feed: ", source.link, err);
}
}); });
} }
}); });