Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(errors): log errors when no error handlers
  • Loading branch information
posva committed Jun 1, 2021
1 parent 9dc994a commit 46a354e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions __tests__/lazyLoading.spec.ts
Expand Up @@ -265,6 +265,7 @@ describe('Lazy Loading', () => {

expect(spy).toHaveBeenCalled()
expect(spy).toHaveBeenLastCalledWith(error)
expect('uncaught error').toHaveBeenWarned()

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

expect(spy).toHaveBeenCalled()
expect('uncaught error').toHaveBeenWarned()

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

expect(spy).toHaveBeenCalledWith(error)
expect('uncaught error').toHaveBeenWarned()

expect(router.currentRoute.value).toMatchObject({
path: '/',
Expand Down
12 changes: 10 additions & 2 deletions src/router.ts
Expand Up @@ -1015,9 +1015,17 @@ export function createRouter(options: RouterOptions): Router {
* @param error - error to throw
* @returns the error as a rejected promise
*/
function triggerError(error: any) {
function triggerError(error: any): Promise<unknown> {
markAsReady(error)
errorHandlers.list().forEach(handler => handler(error))
const list = errorHandlers.list()
if (list.length) {
list.forEach(handler => handler(error))
} else {
if (__DEV__) {
warn('uncaught error during route navigation:')
}
console.error(error)
}
return Promise.reject(error)
}

Expand Down

0 comments on commit 46a354e

Please sign in to comment.