Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(feed): フィード生成コマンドのエラーハンドリング #163

Merged
merged 1 commit into from
Aug 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
})();