From a0321b39b73499cf81430e6390a248bff0f1814f Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 3 Oct 2018 13:03:37 -0400 Subject: [PATCH] refactor: pass target instance to errorCaptured hook --- packages/core/src/component.ts | 6 +++++- packages/core/src/errorHandling.ts | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/core/src/component.ts b/packages/core/src/component.ts index 3cd9ea97..b010e836 100644 --- a/packages/core/src/component.ts +++ b/packages/core/src/component.ts @@ -55,7 +55,11 @@ export interface MountedComponent updated?(vnode: VNode): void beforeUnmount?(): void unmounted?(): void - errorCaptured?(): (err: Error, type: ErrorTypes) => boolean | void + errorCaptured?(): ( + err: Error, + type: ErrorTypes, + target: MountedComponent + ) => boolean | void activated?(): void deactivated?(): void diff --git a/packages/core/src/errorHandling.ts b/packages/core/src/errorHandling.ts index 9294ab50..b6d040f7 100644 --- a/packages/core/src/errorHandling.ts +++ b/packages/core/src/errorHandling.ts @@ -45,17 +45,17 @@ export function handleError( const handler = cur.errorCaptured if (handler) { try { - const captured = handler.call(cur, err, type) + const captured = handler.call(cur, err, type, instance) if (captured) return } catch (err2) { - logError(err2, cur, ErrorTypes.ERROR_CAPTURED) + logError(err2, ErrorTypes.ERROR_CAPTURED) } } } - logError(err, instance, type) + logError(err, type) } -function logError(err: Error, instance: MountedComponent, type: ErrorTypes) { +function logError(err: Error, type: ErrorTypes) { if (__DEV__) { const info = ErrorTypeStrings[type] console.warn(`Unhandled error${info ? ` in ${info}` : ``}:`)