Skip to content

Commit

Permalink
better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumewuip committed Aug 30, 2023
1 parent bc37959 commit f5d6c18
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions rss-to-tana/index.js
Expand Up @@ -101,32 +101,45 @@ function dateDiffInDays(a, b) {

async function extractItems(feed) {
Log.debug(feed.url, '- parsing')

try {
const items = await RSS.parse(feed.url);

return items.map(rssItem => Item.create(rssItem, feed))
} catch (error) {
Log.error(feed.url, `parsing error`, error);
Log.error(`Error extracting items`, feed.url, error);

return []
}
}

// removes items older than 3 days
async function filterOlderItems(items) {
const now = new Date()
return items.filter(item => dateDiffInDays(item.publishedAt, now) < 3)
try {
const now = new Date()
return items.filter(item => dateDiffInDays(item.publishedAt, now) < 3)
} catch (error) {
Log.error(`Error filtering old items`, feed.url, error);

return []
}
}

async function filterSavedItems(items) {
const newItems = []

for (const item of items) {
const itemSavedAlready = await Store.savedAlready(item.id)
try {
for (const item of items) {
const itemSavedAlready = await Store.savedAlready(item.id)

if (!itemSavedAlready) {
newItems.push(item)
if (!itemSavedAlready) {
newItems.push(item)
}
}
} catch (error) {
Log.error(`Error filtering items saved already`, feed.url, error);

return []
}

return newItems
Expand Down

0 comments on commit f5d6c18

Please sign in to comment.