From 1c4601b8dd068e268ed131db1b2a651fe9b33b68 Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Thu, 24 Oct 2024 00:40:38 +0100 Subject: [PATCH] chore: knip --- src/helpers/errors.ts | 8 +++++--- src/worker.ts | 7 +------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/helpers/errors.ts b/src/helpers/errors.ts index e53a425..84da985 100644 --- a/src/helpers/errors.ts +++ b/src/helpers/errors.ts @@ -3,10 +3,12 @@ import { Context } from "../types"; import { addCommentToIssue } from "../handlers/add-comment"; export const logger = new Logs("debug"); -export function handleUncaughtError(err: unknown) { - logger.error("An uncaught error occurred", { err }); - return new Response(JSON.stringify({ err }), { status: 500, headers: { "content-type": "application/json" } }); +export function handleUncaughtError(error: unknown) { + logger.error("An uncaught error occurred", { err: error }); + const status = 500; + return new Response(JSON.stringify({ error }), { status: status, headers: { "content-type": "application/json" } }); } + export function sanitizeMetadata(obj: LogReturn["metadata"]): string { return JSON.stringify(obj, null, 2).replace(//g, ">").replace(/--/g, "--"); } diff --git a/src/worker.ts b/src/worker.ts index b713c77..a8dcee2 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -3,6 +3,7 @@ import { pluginSettingsSchema, pluginSettingsValidator } from "./types"; import { Env, envValidator } from "./types/env"; import manifest from "../manifest.json"; import { plugin } from "./plugin"; +import { handleUncaughtError } from "./helpers/errors"; export default { async fetch(request: Request, env: Env): Promise { @@ -62,9 +63,3 @@ export default { } }, }; - -function handleUncaughtError(error: unknown) { - console.error(error); - const status = 500; - return new Response(JSON.stringify({ error }), { status: status, headers: { "content-type": "application/json" } }); -}