From ba7366c0f96a7e8210ab564f47b6e92eca537875 Mon Sep 17 00:00:00 2001 From: Ender <33337309+e3ndr@users.noreply.github.com> Date: Thu, 21 Sep 2023 17:15:04 -0500 Subject: [PATCH] Public API: Add an error handler. --- public-api/src/main.mjs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/public-api/src/main.mjs b/public-api/src/main.mjs index 49357f8..da2cbf9 100644 --- a/public-api/src/main.mjs +++ b/public-api/src/main.mjs @@ -2,12 +2,17 @@ import * as env from "./env.mjs"; export default { fetch: async function (request, _env) { - console.log("Incoming request!"); - env.configure(_env); + try { + console.log("Incoming request!"); + env.configure(_env); - console.log("Handling request..."); + console.log("Handling request..."); - const router = (await import("./routes/index.mjs")).default; - return await router.handle(request, env); + const router = (await import("./routes/index.mjs")).default; + return await router.handle(request, env); + } catch (e) { + console.error("Internal error:", e.toString(), e.stack); + return new Response("Internal Error."); + } }, };