fix[Mock]: add error handling
This commit is contained in:
		@@ -48,17 +48,21 @@ module.exports = app => {
 | 
				
			|||||||
    ignoreInitial: true
 | 
					    ignoreInitial: true
 | 
				
			||||||
  }).on('all', (event, path) => {
 | 
					  }).on('all', (event, path) => {
 | 
				
			||||||
    if (event === 'change' || event === 'add') {
 | 
					    if (event === 'change' || event === 'add') {
 | 
				
			||||||
      // remove mock routes stack
 | 
					      try {
 | 
				
			||||||
      app._router.stack.splice(mockStartIndex, mockRoutesLength)
 | 
					        // remove mock routes stack
 | 
				
			||||||
 | 
					        app._router.stack.splice(mockStartIndex, mockRoutesLength)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // clear routes cache
 | 
					        // clear routes cache
 | 
				
			||||||
      unregisterRoutes()
 | 
					        unregisterRoutes()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      const mockRoutes = registerRoutes(app)
 | 
					        const mockRoutes = registerRoutes(app)
 | 
				
			||||||
      mockRoutesLength = mockRoutes.mockRoutesLength
 | 
					        mockRoutesLength = mockRoutes.mockRoutesLength
 | 
				
			||||||
      mockStartIndex = mockRoutes.mockStartIndex
 | 
					        mockStartIndex = mockRoutes.mockStartIndex
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      console.log(chalk.magentaBright(`\n > Mock Server hot reload success! changed  ${path}`))
 | 
					        console.log(chalk.magentaBright(`\n > Mock Server hot reload success! changed  ${path}`))
 | 
				
			||||||
 | 
					      } catch (error) {
 | 
				
			||||||
 | 
					        console.log(chalk.redBright(error))
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user