refactor: pass target instance to errorCaptured hook
This commit is contained in:
parent
d893046830
commit
a0321b39b7
@ -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
|
||||
|
||||
|
@ -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}` : ``}:`)
|
||||
|
Loading…
Reference in New Issue
Block a user