-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbug-reporter.ts
32 lines (28 loc) · 1.3 KB
/
bug-reporter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// @deno-types="https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/types/platform/index.d.ts"
import browser from "https://unpkg.com/[email protected]/platform.js";
import { API } from "./spec/mod.ts";
globalThis.onunhandledrejection = (e) => {
report(e.reason);
};
globalThis.onerror = (e) => {
report(typeof e == "string" ? e : (<ErrorEvent> e).error);
};
function report(msg: any) {
if (["ResizeObserver loop completed with undelivered notifications.", "ResizeObserver loop limit exceeded", "Uncaught aborting javascript here"].includes(msg)) return;
API.postBugTrack({
body: {
type: "web-frontend",
platform: browser.os?.family,
platformVersion: browser.os?.version,
error: msg instanceof Error ? msg.message : msg,
errorStack: (msg instanceof Error ? msg.stack : msg),
browser: browser.name,
// null safe version of getting the error
userId: localStorage["access-token"]?.split(".").filter((_: string, i: number) => i <= 1).map((x: string) => JSON.parse(atob(x))).filter((_: string, i: number) => i == 1).map((it: any) => it.userId).join(),
browserVersion: browser.version,
location: location.toString(),
},
}).catch(() => {
//
});
}