feat(runtime-vapor): add app-level error handler (#160)

Co-authored-by: Kevin Deng 三咲智子 <sxzz@sxzz.moe>
This commit is contained in:
Doctor Wu 2024-03-23 00:38:34 +08:00 committed by GitHub
parent 5c9a15140d
commit bd888b9b1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 12 deletions

View File

@ -7,7 +7,11 @@ import type { ComponentInternalInstance } from './component'
import { isFunction, isPromise } from '@vue/shared'
import { warn } from './warning'
import { VaporLifecycleHooks } from './apiLifecycle'
import { BaseWatchErrorCodes } from '@vue/reactivity'
import {
BaseWatchErrorCodes,
pauseTracking,
resetTracking,
} from '@vue/reactivity'
// contexts where user provided function may be executed, in addition to
// lifecycle hooks.
@ -131,18 +135,19 @@ export function handleError(
cur = cur.parent
}
// TODO: need appContext interface
// app-level handling
// const appErrorHandler = instance.appContext?.config.errorHandler
// if (appErrorHandler) {
// callWithErrorHandling(
// appErrorHandler,
// null,
// ErrorCodes.APP_ERROR_HANDLER,
// [err, exposedInstance, errorInfo],
// )
// return
// }
const appErrorHandler = instance.appContext.config.errorHandler
if (appErrorHandler) {
pauseTracking()
callWithErrorHandling(
appErrorHandler,
null,
VaporErrorCodes.APP_ERROR_HANDLER,
[err, instance, errorInfo],
)
resetTracking()
return
}
}
logError(err, type, throwInDev)
}