Closed frenzzy closed 6 years ago
Add an option for global error handling:
import UniversalRouter from 'universal-router' const routes = [ { path: '/one', action: () => '<h1>Page One</h1>' }, { path: '/two', action: () => '<h1>Page Two</h1>' } ] const options = { errorHandler(error) { // <= new option console.error(error) console.dir(error.context) return error.code === 404 ? '<h1>Page Not Found</h1>' : '<h1>Oops! Something went wrong</h1>' } } const router = new UniversalRouter(routes, options) router.resolve('/random').then(result => { document.body.innerHTML = result // renders: <h1>Page Not Found</h1> })
Coverage remained the same at 100.0% when pulling 122072d7a4ec0a871a43e6d2ef2b5397f84e9e8e on frenzzy:error-handler into 30a82112813d19ebef5302e964cc9a21928d5323 on kriasoft:master.
Add an option for global error handling: