refactor: pass target instance to errorCaptured hook

This commit is contained in:
Evan You 2018-10-03 13:03:37 -04:00
parent d893046830
commit a0321b39b7
2 changed files with 9 additions and 5 deletions

View File

@ -55,7 +55,11 @@ export interface MountedComponent<D = Data, P = Data>
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

View File

@ -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}` : ``}:`)