Skip to content

Commit 46a354e

Browse files
committed
feat(errors): log errors when no error handlers
1 parent 9dc994a commit 46a354e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

__tests__/lazyLoading.spec.ts

+3
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ describe('Lazy Loading', () => {
265265

266266
expect(spy).toHaveBeenCalled()
267267
expect(spy).toHaveBeenLastCalledWith(error)
268+
expect('uncaught error').toHaveBeenWarned()
268269

269270
expect(router.currentRoute.value).toMatchObject({
270271
path: '/',
@@ -284,6 +285,7 @@ describe('Lazy Loading', () => {
284285
await router.push('/foo').catch(spy)
285286

286287
expect(spy).toHaveBeenCalled()
288+
expect('uncaught error').toHaveBeenWarned()
287289

288290
expect(router.currentRoute.value).toMatchObject({
289291
path: '/',
@@ -312,6 +314,7 @@ describe('Lazy Loading', () => {
312314
await router.push('/foo').catch(spy)
313315

314316
expect(spy).toHaveBeenCalledWith(error)
317+
expect('uncaught error').toHaveBeenWarned()
315318

316319
expect(router.currentRoute.value).toMatchObject({
317320
path: '/',

src/router.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1015,9 +1015,17 @@ export function createRouter(options: RouterOptions): Router {
10151015
* @param error - error to throw
10161016
* @returns the error as a rejected promise
10171017
*/
1018-
function triggerError(error: any) {
1018+
function triggerError(error: any): Promise<unknown> {
10191019
markAsReady(error)
1020-
errorHandlers.list().forEach(handler => handler(error))
1020+
const list = errorHandlers.list()
1021+
if (list.length) {
1022+
list.forEach(handler => handler(error))
1023+
} else {
1024+
if (__DEV__) {
1025+
warn('uncaught error during route navigation:')
1026+
}
1027+
console.error(error)
1028+
}
10211029
return Promise.reject(error)
10221030
}
10231031

0 commit comments

Comments
 (0)