From bb80359432a2459c933efb3b733d3a4f25aea665 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 17 Apr 2018 18:04:16 +0200 Subject: [PATCH] Added client error reports --- scripts/AnimeNotifier.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index 6907e1af..5a361d1a 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -85,6 +85,7 @@ export default class AnimeNotifier { document.addEventListener("DOMContentLoaded", this.onContentLoaded.bind(this)) document.addEventListener("keydown", this.onKeyDown.bind(this), false) window.addEventListener("popstate", this.onPopState.bind(this)) + window.addEventListener("error", this.onError.bind(this)) // Idle requestIdleCallback(this.onIdle.bind(this)) @@ -1024,4 +1025,19 @@ export default class AnimeNotifier { return } } + + // This is called every time an uncaught JavaScript error is thrown + onError(evt: ErrorEvent) { + let report = { + message: evt.message, + stack: evt.error.stack, + fileName: evt.filename, + lineNumber: evt.lineno, + columnNumber: evt.colno, + } + + this.post("/api/new/clienterrorreport", report) + .then(() => console.log("Successfully reported the error to the website staff.")) + .catch(() => console.warn("Failed reporting the error to the website staff.")) + } } \ No newline at end of file