From 3324aedbf6c8ec6b9aa5b00bf6c9b0bc3e9770d2 Mon Sep 17 00:00:00 2001 From: danbulant Date: Sun, 16 Feb 2020 10:24:59 +0100 Subject: [PATCH] Remap console to catch reload errors --- client/src/index.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/client/src/index.ts b/client/src/index.ts index 4f91de8..dd2de92 100644 --- a/client/src/index.ts +++ b/client/src/index.ts @@ -1,5 +1,25 @@ import boot from './managers/boot'; +//Remap console (so console.error is catched by error handler) +var console = (function (oldCons) { + return { + ...oldCons, + error: function (text:any) { + if(text instanceof Error){ + throw text; + } else { + throw Error(text); + } + } + }; + +}(window.console)); + +//Make console writeable +type Writeable = { -readonly [P in keyof T]: T[P] }; + +(window as Writeable).console = console; + //Handle errors window.onerror = (msg, url, line, col, error)=>{ var e = document.createElement("div");