Skip to content

Commit

Permalink
Merge pull request #163 from yamadashy/feature/error-handling
Browse files Browse the repository at this point in the history
feat(feed): フィード生成コマンドのエラーハンドリング
  • Loading branch information
yamadashy authored Aug 24, 2024
2 parents b45ddac + bee9831 commit e2371f2
Showing 1 changed file with 41 additions and 17 deletions.
58 changes: 41 additions & 17 deletions src/feed/generate-feed-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,49 @@ const feedImagePrecacher = new FeedImagePrecacher();
);

// まとめフィードのバリデーション。エラーならすぐに終了する
await feedValidator.assertFeed(generateFeedsResult.aggregatedFeed);
await feedValidator.assertXmlFeed('atom', generateFeedsResult.feedDistributionSet.atom);
await feedValidator.assertXmlFeed('rss', generateFeedsResult.feedDistributionSet.rss);
try {
await feedValidator.assertFeed(generateFeedsResult.aggregatedFeed);
await feedValidator.assertXmlFeed('atom', generateFeedsResult.feedDistributionSet.atom);
await feedValidator.assertXmlFeed('rss', generateFeedsResult.feedDistributionSet.rss);
} catch (e) {
const error = new Error('Failed to validate feed', {
cause: e,
});
console.error(error);
throw error;
}

// ファイル出力
await feedStorer.storeFeeds(
generateFeedsResult.feedDistributionSet,
STORE_FEEDS_DIR_PATH,
crawlFeedsResult.feeds,
ogObjectMap,
crawlFeedsResult.feedItemHatenaCountMap,
STORE_BLOG_FEEDS_DIR_PATH,
);
try {
await feedStorer.storeFeeds(
generateFeedsResult.feedDistributionSet,
STORE_FEEDS_DIR_PATH,
crawlFeedsResult.feeds,
ogObjectMap,
crawlFeedsResult.feedItemHatenaCountMap,
STORE_BLOG_FEEDS_DIR_PATH,
);
} catch (e) {
const error = new Error('Failed to store feeds', {
cause: e,
});
console.error(error);
throw error;
}

// 画像の事前キャッシュ
await feedImagePrecacher.fetchAndCacheFeedImages(
crawlFeedsResult.feeds,
crawlFeedsResult.feedItems,
ogObjectMap,
FETCH_IMAGE_CONCURRENCY,
);
try {
await feedImagePrecacher.fetchAndCacheFeedImages(
crawlFeedsResult.feeds,
crawlFeedsResult.feedItems,
ogObjectMap,
FETCH_IMAGE_CONCURRENCY,
);
} catch (e) {
const error = new Error('Failed to cache feed images', {
cause: e,
});
console.error(error);
throw error;
}
})();

0 comments on commit e2371f2

Please sign in to comment.