From 0bb67a66004b54db94036247269402272b55ab08 Mon Sep 17 00:00:00 2001 From: Jonas Strehle Date: Tue, 13 Feb 2024 11:06:59 +0100 Subject: [PATCH] Fix unhandled rejection reporting / crash --- init.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/init.ts b/init.ts index 08f087f6..7a3059eb 100644 --- a/init.ts +++ b/init.ts @@ -21,13 +21,14 @@ import { sendReport } from "./utils/error-reporting.ts"; if (client_type == "deno") { globalThis.addEventListener("unhandledrejection", (e: PromiseRejectionEvent) => { const error = e.reason instanceof Error ? - { message: e.reason.message, stack: e.reason.stack } : + { name: e.reason.name, message: e.reason.message, stack: e.reason.stack } : e.reason ?? e; - console.error("Uncaught promise:", e.promise, e.reason); + console.error("Uncaught promise:", e.promise); - if (error?.message?.includes("BadResource") || error?.includes?.("BadResource")) { + if (error?.message?.includes("BadResource") || error?.includes?.("BadResource") || error?.name === "BadResource") { + console.debug("Handeled rejection"); e.preventDefault(); - sendReport("unhandledrejection", e instanceof Error ? {message: e.message, stack: e.stack} : e) + sendReport("unhandledrejection", error) .catch(console.error) } });