feat: improve error handling for authentication flow
This commit is contained in:
@@ -4,11 +4,11 @@ import { streamSSE } from "hono/streaming";
|
||||
|
||||
import { fetchEpisodes } from "~/controllers/episodes/getByAniListId";
|
||||
import { maybeScheduleNextAiringEpisode } from "~/libs/maybeScheduleNextAiringEpisode";
|
||||
import { readEnvVariable } from "~/libs/readEnvVariable";
|
||||
import { sleep } from "~/libs/sleep";
|
||||
import { associateDeviceIdWithUsername } from "~/models/token";
|
||||
import { setWatchStatus } from "~/models/watchStatus";
|
||||
import type { Env } from "~/types/env";
|
||||
import { EpisodesResponseSchema } from "~/types/episode";
|
||||
import { Episode, EpisodesResponseSchema } from "~/types/episode";
|
||||
import { ErrorResponse, ErrorResponseSchema } from "~/types/schema";
|
||||
import { Title } from "~/types/title";
|
||||
|
||||
@@ -137,7 +137,6 @@ app.openapi(route, async (c) => {
|
||||
user.name!,
|
||||
currentPage++,
|
||||
aniListToken,
|
||||
c.executionCtx,
|
||||
);
|
||||
if (!mediaList) {
|
||||
break;
|
||||
@@ -151,7 +150,7 @@ app.openapi(route, async (c) => {
|
||||
}
|
||||
|
||||
for (const mediaObj of mediaList) {
|
||||
const media = mediaObj?.media!;
|
||||
const media = mediaObj?.media;
|
||||
if (!media) {
|
||||
continue;
|
||||
}
|
||||
@@ -189,8 +188,14 @@ app.openapi(route, async (c) => {
|
||||
|
||||
await fetchEpisodes(
|
||||
media.id,
|
||||
readEnvVariable<boolean>(c.env, "ENABLE_ANIFY"),
|
||||
).then(({ result: { episodes } }) => {
|
||||
{ ...env(c, "workerd"), ENABLE_ANIFY: "false" },
|
||||
true,
|
||||
).then(({ result: episodesResult }) => {
|
||||
const episodes = episodesResult?.episodes;
|
||||
if (!episodes) {
|
||||
return;
|
||||
}
|
||||
|
||||
stream.writeSSE({
|
||||
event: "title",
|
||||
data: JSON.stringify({ title: media, episodes }),
|
||||
@@ -199,15 +204,13 @@ app.openapi(route, async (c) => {
|
||||
});
|
||||
}
|
||||
|
||||
hasNextPage = pageInfo?.hasNextPage ?? false;
|
||||
hasNextPage = pageInfo?.hasNextPage ?? false;
|
||||
console.log(hasNextPage);
|
||||
hasNextPage = pageInfo?.hasNextPage ?? false;
|
||||
console.log(hasNextPage);
|
||||
} while (hasNextPage);
|
||||
|
||||
// send end event instead of closing the connection to let the client know that the stream didn't end abruptly
|
||||
await stream.writeSSE({ event: "end", data: "end" });
|
||||
console.log("completed");
|
||||
},
|
||||
async (err, stream) => {
|
||||
console.error("Error occurred in SSE");
|
||||
|
||||
Reference in New Issue
Block a user