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);
//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);
}
});
}
});