From 9c28b1dd924fe0a2d8541759569fda046fb62eb7 Mon Sep 17 00:00:00 2001 From: Pan Date: Sun, 28 Apr 2019 17:53:07 +0800 Subject: [PATCH] fix[Mock]: add error handling --- mock/mock-server.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/mock/mock-server.js b/mock/mock-server.js index ccce04d2..4c4cb2af 100644 --- a/mock/mock-server.js +++ b/mock/mock-server.js @@ -48,17 +48,21 @@ module.exports = app => { ignoreInitial: true }).on('all', (event, path) => { if (event === 'change' || event === 'add') { - // remove mock routes stack - app._router.stack.splice(mockStartIndex, mockRoutesLength) + try { + // remove mock routes stack + app._router.stack.splice(mockStartIndex, mockRoutesLength) - // clear routes cache - unregisterRoutes() + // clear routes cache + unregisterRoutes() - const mockRoutes = registerRoutes(app) - mockRoutesLength = mockRoutes.mockRoutesLength - mockStartIndex = mockRoutes.mockStartIndex + const mockRoutes = registerRoutes(app) + mockRoutesLength = mockRoutes.mockRoutesLength + 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)) + } } }) }