Skip to content

Commit

Permalink
Backend unhandled browser promise rejection
Browse files Browse the repository at this point in the history
  • Loading branch information
N2D4 committed Dec 11, 2024
1 parent c8a1c19 commit e6ed451
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions apps/backend/src/polyfills.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import * as util from "util";
import { captureError, registerErrorSink } from "@stackframe/stack-shared/dist/utils/errors";
import * as Sentry from "@sentry/nextjs";
import { getNodeEnvironment } from "@stackframe/stack-shared/dist/utils/env";
import { captureError, registerErrorSink } from "@stackframe/stack-shared/dist/utils/errors";
import * as util from "util";

const sentryErrorSink = (location: string, error: unknown) => {
Sentry.captureException(error, { extra: { location } });
};

export function ensurePolyfilled() {
registerErrorSink(sentryErrorSink);

window.addEventListener("unhandledrejection", (event) => {
captureError("unhandled-browser-promise-rejection", event.reason);
console.error("Unhandled promise rejection", event.reason);
});

// not all environments have default options for util.inspect
if ("inspect" in util && "defaultOptions" in util.inspect) {
util.inspect.defaultOptions.depth = 8;
Expand Down

0 comments on commit e6ed451

Please sign in to comment.