From cf02319c34164dbd427bc4c5eab2be2e3b28ca73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Thu, 16 Mar 2023 15:33:59 +0100 Subject: [PATCH] [REF] app: move app specific error handling code It was before in the generic error handling file. However, since it is there, it is not possible to modify this behaviour by subclassing App. Another usecase would be for the devtools extension: with this commit, it is now easily able to listen to app destruction events. --- src/runtime/app.ts | 10 ++++++++++ src/runtime/error_handling.ts | 8 +------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/runtime/app.ts b/src/runtime/app.ts index caca43f5..c018797c 100644 --- a/src/runtime/app.ts +++ b/src/runtime/app.ts @@ -213,6 +213,16 @@ export class App< handleError(...args: Parameters) { return handleError(...args); } + + onUnhandledError(error: Error) { + console.warn(`[Owl] Unhandled error. Destroying the root component`); + try { + this.destroy(); + } catch (e) { + console.error(e); + } + throw error; + } } export async function mount< diff --git a/src/runtime/error_handling.ts b/src/runtime/error_handling.ts index 4b4134d6..8a51001a 100644 --- a/src/runtime/error_handling.ts +++ b/src/runtime/error_handling.ts @@ -65,12 +65,6 @@ export function handleError(params: ErrorParams) { const handled = _handleError(node, error); if (!handled) { - console.warn(`[Owl] Unhandled error. Destroying the root component`); - try { - node.app.destroy(); - } catch (e) { - console.error(e); - } - throw error; + node.app.onUnhandledError(error); } }