Skip to content

Commit bd888b9

Browse files
Doctor-wusxzz
andauthored
feat(runtime-vapor): add app-level error handler (#160)
Co-authored-by: Kevin Deng 三咲智子 <sxzz@sxzz.moe>
1 parent 5c9a151 commit bd888b9

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

packages/runtime-vapor/src/errorHandling.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import type { ComponentInternalInstance } from './component'
77
import { isFunction, isPromise } from '@vue/shared'
88
import { warn } from './warning'
99
import { VaporLifecycleHooks } from './apiLifecycle'
10-
import { BaseWatchErrorCodes } from '@vue/reactivity'
10+
import {
11+
BaseWatchErrorCodes,
12+
pauseTracking,
13+
resetTracking,
14+
} from '@vue/reactivity'
1115

1216
// contexts where user provided function may be executed, in addition to
1317
// lifecycle hooks.
@@ -131,18 +135,19 @@ export function handleError(
131135
cur = cur.parent
132136
}
133137

134-
// TODO: need appContext interface
135138
// app-level handling
136-
// const appErrorHandler = instance.appContext?.config.errorHandler
137-
// if (appErrorHandler) {
138-
// callWithErrorHandling(
139-
// appErrorHandler,
140-
// null,
141-
// ErrorCodes.APP_ERROR_HANDLER,
142-
// [err, exposedInstance, errorInfo],
143-
// )
144-
// return
145-
// }
139+
const appErrorHandler = instance.appContext.config.errorHandler
140+
if (appErrorHandler) {
141+
pauseTracking()
142+
callWithErrorHandling(
143+
appErrorHandler,
144+
null,
145+
VaporErrorCodes.APP_ERROR_HANDLER,
146+
[err, instance, errorInfo],
147+
)
148+
resetTracking()
149+
return
150+
}
146151
}
147152
logError(err, type, throwInDev)
148153
}

0 commit comments

Comments
 (0)