feat: add more error handling
This commit is contained in:
@@ -3,6 +3,7 @@ import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
||||
import { fetchFromMultipleSources } from "~/libs/fetchFromMultipleSources";
|
||||
import {
|
||||
AniListIdQuerySchema,
|
||||
ErrorResponse,
|
||||
ErrorResponseSchema,
|
||||
SuccessResponseSchema,
|
||||
} from "~/types/schema";
|
||||
@@ -47,12 +48,17 @@ app.openapi(route, async (c) => {
|
||||
const aniListId = Number(c.req.query("id"));
|
||||
const aniListToken = c.req.header("X-AniList-Token");
|
||||
|
||||
const title = await fetchFromMultipleSources([
|
||||
const { result: title, errors } = await fetchFromMultipleSources([
|
||||
() => fetchTitleFromAnilist(aniListId, aniListToken ?? undefined),
|
||||
() => fetchTitleFromAmvstrm(aniListId),
|
||||
]);
|
||||
|
||||
if (errors?.length > 0) {
|
||||
return c.json(ErrorResponse, { status: 500 });
|
||||
}
|
||||
|
||||
if (!title) {
|
||||
return c.json({ success: false }, 404);
|
||||
return c.json(ErrorResponse, 404);
|
||||
}
|
||||
|
||||
return c.json({ success: true, result: title }, 200);
|
||||
|
||||
Reference in New Issue
Block a user