1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Catch router events errors and print them. (#2663)

This commit is contained in:
Arunoda Susiripala 2017-07-27 19:20:39 +05:30 committed by GitHub
parent cf130c70f0
commit cc9b1d6ce0

View file

@ -42,7 +42,12 @@ routerEvents.forEach((event) => {
SingletonRouter.router.events.on(event, (...args) => { SingletonRouter.router.events.on(event, (...args) => {
const eventField = `on${event.charAt(0).toUpperCase()}${event.substring(1)}` const eventField = `on${event.charAt(0).toUpperCase()}${event.substring(1)}`
if (SingletonRouter[eventField]) { if (SingletonRouter[eventField]) {
try {
SingletonRouter[eventField](...args) SingletonRouter[eventField](...args)
} catch (err) {
console.error(`Error when running the Router event: ${eventField}`)
console.error(`${err.message}\n${err.stack}`)
}
} }
}) })
}) })