Skip to content

Commit

Permalink
Improve error handling for invalid rss feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorsharp committed Jan 6, 2025
1 parent b2c4522 commit f6e0425
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"react-hook-form": "^7.51.3",
"server-only": "^0.0.1",
"superjson": "^2.2.1",
"zod": "^3.22.4"
"zod": "^3.24.1"
},
"devDependencies": {
"@types/eslint": "^8.56.2",
Expand Down
7 changes: 4 additions & 3 deletions src/services/feedService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const fetchFeedData = async (urls: string[], searchParams?: URLSearchParams) =>
.then((response) => response.text())
.then((data) => parseFeed(data))
.catch((error) => {
console.log(error);
console.error(error);
return undefined;
});
}),
Expand All @@ -59,9 +59,10 @@ const fetchFeedData = async (urls: string[], searchParams?: URLSearchParams) =>
);
};

const parseFeed = (rawFeed: string): FeedData => {
const parseFeed = (rawFeed: string): FeedData | undefined => {
const parsedFeed = parser.parse(rawFeed) as unknown;
return feedSchema.parse(parsedFeed);
const { data: feedData, success } = feedSchema.safeParse(parsedFeed);
return success ? feedData : undefined;
};

const mergeFeeds = (mainFeed: FeedData, additionalFeeds: FeedData[]) => {
Expand Down

0 comments on commit f6e0425

Please sign in to comment.