From 64777956ef2ef1cb752fc057644ba39a05b31979 Mon Sep 17 00:00:00 2001 From: Anton Dosov Date: Thu, 28 Apr 2022 15:20:05 +0200 Subject: [PATCH 1/2] very basic runtime error handling --- src/plugins/vis_type_script/public/renderer/index.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/plugins/vis_type_script/public/renderer/index.tsx b/src/plugins/vis_type_script/public/renderer/index.tsx index b102a809b1ed7..56e742e440ef1 100644 --- a/src/plugins/vis_type_script/public/renderer/index.tsx +++ b/src/plugins/vis_type_script/public/renderer/index.tsx @@ -53,6 +53,11 @@ const getSandboxDocument = (script: string, dependencies: string[], nonce: strin window.addEventListener('resize', () => onResize(window.innerWidth, window.innerHeight)); + // TODO a nicer error: + document.body.innerHTML = "

" + (e.reason || e.message || e).toString() + "

" + "" + (e.reason || e).stack || '' + ""; + } + window.addEventListener('error', handleGlobalError); + window.addEventListener('unhandledrejection', handleGlobalError); From 1939783ed220a8ed8e0e6cd2d9673d17790614dc Mon Sep 17 00:00:00 2001 From: Anton Dosov Date: Thu, 28 Apr 2022 15:21:12 +0200 Subject: [PATCH 2/2] very basic error handling --- src/plugins/vis_type_script/public/renderer/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugins/vis_type_script/public/renderer/index.tsx b/src/plugins/vis_type_script/public/renderer/index.tsx index 56e742e440ef1..85ef0af41e884 100644 --- a/src/plugins/vis_type_script/public/renderer/index.tsx +++ b/src/plugins/vis_type_script/public/renderer/index.tsx @@ -53,6 +53,8 @@ const getSandboxDocument = (script: string, dependencies: string[], nonce: strin window.addEventListener('resize', () => onResize(window.innerWidth, window.innerHeight)); + function handleGlobalError(e) { + console.error(e); // TODO a nicer error: document.body.innerHTML = "

" + (e.reason || e.message || e).toString() + "

" + "" + (e.reason || e).stack || '' + ""; }