feat: add more error handling

This commit is contained in:
2024-06-07 23:13:30 -04:00
parent 6fd2cc4feb
commit c35c9b9e09
9 changed files with 71 additions and 66 deletions

View File

@@ -39,12 +39,17 @@ app.openapi(route, async (c) => {
const page = Number(c.req.query("page") ?? 1);
const limit = Number(c.req.query("limit") ?? 10);
const response = await fetchFromMultipleSources([
const { result: response, errors } = await fetchFromMultipleSources([
() => fetchSearchResultsFromAnilist(query, page, limit),
() => fetchSearchResultsFromAmvstrm(query, page, limit),
]);
if (!response) {
return c.json({ success: false, results: [], hasNextPage: false }, 200);
return c.json({
success: (errors ?? []).length === 0,
results: [],
hasNextPage: false,
});
}
return c.json(