Skip to content

Commit

Permalink
Merge pull request #85 from unyt-org/jonasstrehle-patch-1
Browse files Browse the repository at this point in the history
Fix unhandled rejection reporting / crash
  • Loading branch information
benStre authored Feb 13, 2024
2 parents 8020736 + 0bb67a6 commit 763fdc5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
});
Expand Down

0 comments on commit 763fdc5

Please sign in to comment.