feat: improve error handling for authentication flow
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
||||
import { env } from "hono/adapter";
|
||||
|
||||
import { fetchFromMultipleSources } from "~/libs/fetchFromMultipleSources";
|
||||
import { readEnvVariable } from "~/libs/readEnvVariable";
|
||||
@@ -45,13 +46,13 @@ const app = new OpenAPIHono<Env>();
|
||||
|
||||
export function fetchEpisodesFromAllProviders(
|
||||
aniListId: number,
|
||||
isAnifyEnabled: boolean,
|
||||
env: Env,
|
||||
): Promise<EpisodesResponse[]> {
|
||||
return Promise.allSettled([
|
||||
import("./aniwatch").then(({ getEpisodesFromAniwatch }) =>
|
||||
getEpisodesFromAniwatch(aniListId),
|
||||
),
|
||||
getEpisodesFromAnify(isAnifyEnabled, aniListId),
|
||||
getEpisodesFromAnify(env, aniListId),
|
||||
]).then((episodeResults) =>
|
||||
episodeResults
|
||||
.filter((result) => result.status === "fulfilled")
|
||||
@@ -60,16 +61,20 @@ export function fetchEpisodesFromAllProviders(
|
||||
);
|
||||
}
|
||||
|
||||
export function fetchEpisodes(aniListId: number, isAnifyEnabled: boolean) {
|
||||
export function fetchEpisodes(
|
||||
aniListId: number,
|
||||
env: Env,
|
||||
shouldRetry: boolean = false,
|
||||
) {
|
||||
return fetchFromMultipleSources([
|
||||
() => getEpisodesFromAnify(isAnifyEnabled, aniListId),
|
||||
() => getEpisodesFromAnify(env, aniListId),
|
||||
// () =>
|
||||
// import("./consumet").then(({ getEpisodesFromConsumet }) =>
|
||||
// getEpisodesFromConsumet(aniListId),
|
||||
// ),
|
||||
() =>
|
||||
import("./aniwatch").then(({ getEpisodesFromAniwatch }) =>
|
||||
getEpisodesFromAniwatch(aniListId),
|
||||
getEpisodesFromAniwatch(aniListId, shouldRetry),
|
||||
),
|
||||
]);
|
||||
}
|
||||
@@ -79,7 +84,7 @@ app.openapi(route, async (c) => {
|
||||
|
||||
const { result: episodes, errorOccurred } = await fetchEpisodes(
|
||||
aniListId,
|
||||
readEnvVariable<boolean>(c.env, "ENABLE_ANIFY"),
|
||||
env(c, "workerd"),
|
||||
);
|
||||
|
||||
if (errorOccurred) {
|
||||
|
||||
Reference in New Issue
Block a user