fix: fetchFromMultipleSources returns errorOccurred only if all sources fail

This commit is contained in:
2024-06-07 23:42:41 -04:00
parent c35c9b9e09
commit 1ccd004c77
5 changed files with 21 additions and 25 deletions

View File

@@ -49,7 +49,7 @@ const app = new OpenAPIHono<Env>();
app.openapi(route, async (c) => {
const aniListId = Number(c.req.param("aniListId"));
const { result: episodes, errors } = await fetchFromMultipleSources([
const { result: episodes, errorOccurred } = await fetchFromMultipleSources([
() => {
const isAnifyEnabled = readEnvVariable<boolean>(c.env, "ENABLE_ANIFY");
return getEpisodesFromAnify(isAnifyEnabled, aniListId);
@@ -64,7 +64,7 @@ app.openapi(route, async (c) => {
),
]);
if (errors?.length > 0) {
if (errorOccurred) {
return c.json(ErrorResponse, { status: 500 });
}