fix: improve error logging

Cloudflare doesn't log causes, only the messages so splitting the logs in to 2
This commit is contained in:
2024-10-27 08:48:55 -04:00
parent 34958cfa69
commit 2dcf8630ab
9 changed files with 16 additions and 32 deletions

View File

@@ -107,7 +107,7 @@ app.openapi(route, async (c) => {
return c.json(ErrorResponse, { status: 401 }); return c.json(ErrorResponse, { status: 401 });
} }
} catch (error) { } catch (error) {
console.error(new Error("Failed to authenticate with AniList")); console.error("Failed to authenticate with AniList");
console.error(error); console.error(error);
return c.json(ErrorResponse, { status: 500 }); return c.json(ErrorResponse, { status: 500 });
} }
@@ -119,7 +119,7 @@ app.openapi(route, async (c) => {
user.name!, user.name!,
); );
} catch (error) { } catch (error) {
console.error(new Error("Failed to associate device")); console.error("Failed to associate device");
console.error(error); console.error(error);
return c.json(ErrorResponse, { status: 500 }); return c.json(ErrorResponse, { status: 500 });
} }

View File

@@ -46,11 +46,9 @@ export async function getEpisodesFromAnify(
abortController.abort("Loading episodes from Anify timed out"); abortController.abort("Loading episodes from Anify timed out");
} }
console.error( console.error(
new Error(
`Error trying to load episodes from anify; aniListId: ${aniListId}`, `Error trying to load episodes from anify; aniListId: ${aniListId}`,
{ cause: e },
),
); );
console.error(e);
} }
if (!response || response.length === 0) { if (!response || response.length === 0) {

View File

@@ -68,11 +68,9 @@ export async function getEpisodesFromAniwatch(
} }
console.error( console.error(
new Error(
`Error trying to load episodes from aniwatch; aniListId: ${aniListId}`, `Error trying to load episodes from aniwatch; aniListId: ${aniListId}`,
{ cause: error },
),
); );
console.error(error);
} }
return null; return null;

View File

@@ -29,11 +29,9 @@ export async function getEpisodesFromConsumet(
} catch (error: any) { } catch (error: any) {
if (!error.message.includes("failed with status code")) { if (!error.message.includes("failed with status code")) {
console.error( console.error(
new Error(
`Error trying to load episodes from consumet; aniListId: ${aniListId}`, `Error trying to load episodes from consumet; aniListId: ${aniListId}`,
{ cause: error },
),
); );
console.error(error);
} }
} }

View File

@@ -29,15 +29,6 @@ export async function markEpisodeAsWatched(
) { ) {
const client = new GraphQLClient("https://graphql.anilist.co/"); const client = new GraphQLClient("https://graphql.anilist.co/");
console.log(aniListToken);
console.log(
typeof aniListToken,
titleId,
typeof titleId,
episodeNumber,
typeof episodeNumber,
markTitleAsComplete,
);
const mutation = markTitleAsComplete const mutation = markTitleAsComplete
? client.request( ? client.request(
MarkTitleAsWatchedMutation, MarkTitleAsWatchedMutation,

View File

@@ -94,9 +94,8 @@ app.openapi(route, async (c) => {
); );
} }
} catch (error) { } catch (error) {
console.error( console.error("Failed to mark episode as watched");
new Error("Failed to mark episode as watched", { cause: error }), console.error(error);
);
return c.json(ErrorResponse, { status: 500 }); return c.json(ErrorResponse, { status: 500 });
} }

View File

@@ -78,7 +78,8 @@ app.openapi(route, async (c) => {
await saveToken(env(c, "workerd"), deviceId, token); await saveToken(env(c, "workerd"), deviceId, token);
} catch (error) { } catch (error) {
console.error(new Error("Failed to save token", { cause: error })); console.error("Failed to save token");
console.error(error);
return c.json(ErrorResponse, 500); return c.json(ErrorResponse, 500);
} }

View File

@@ -105,7 +105,7 @@ app.openapi(route, async (c) => {
watchStatus, watchStatus,
); );
} catch (error) { } catch (error) {
console.error(new Error("Error setting watch status", { cause: error })); console.error("Error setting watch status");
console.error(error); console.error(error);
return c.json(ErrorResponse, { status: 500 }); return c.json(ErrorResponse, { status: 500 });
} }
@@ -118,9 +118,8 @@ app.openapi(route, async (c) => {
aniListToken, aniListToken,
); );
} catch (error) { } catch (error) {
console.error( console.error("Failed to update watch status on Anilist");
new Error("Failed to update watch status on Anilist", { cause: error }), console.error(error);
);
if (isRetrying) { if (isRetrying) {
return c.json(ErrorResponse, { status: 500 }); return c.json(ErrorResponse, { status: 500 });
} }

View File

@@ -77,7 +77,7 @@ export async function queueTask(
.update(task.name.split("/").at(-1)!) .update(task.name.split("/").at(-1)!)
.digest("hex"), .digest("hex"),
); );
console.log(hashedTaskName); console.log("task name", hashedTaskName);
const { res } = await queueCloudTask({ const { res } = await queueCloudTask({
...task, ...task,
name: name: