]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
feat(errors): log errors when no error handlers
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 1 Jun 2021 22:01:57 +0000 (00:01 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 1 Jun 2021 22:01:57 +0000 (00:01 +0200)
__tests__/lazyLoading.spec.ts
src/router.ts

index 9c95a33a5081508de10e5bdd798cdd1568032999..e50d8fb52b9e3c6c4fb56558a4a0afbfaf430f71 100644 (file)
@@ -265,6 +265,7 @@ describe('Lazy Loading', () => {
 
     expect(spy).toHaveBeenCalled()
     expect(spy).toHaveBeenLastCalledWith(error)
+    expect('uncaught error').toHaveBeenWarned()
 
     expect(router.currentRoute.value).toMatchObject({
       path: '/',
@@ -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: '/',
@@ -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: '/',
index 1825a3e0561a643d24ebbf9a6ee69495220cfd18..9393ddccaed17532580c9c8837edbbd0dc38f51b 100644 (file)
@@ -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)
   }