Commit 23978698 authored by Bendik Aagaard Lynghaug's avatar Bendik Aagaard Lynghaug Committed by Renée Kooi
Browse files

Catch routing errors when attempting to render missing routes (#457)

* #456 dont throw on choo ssr missing a wildcard route

* update to catch any error occurring in rendering

* no console statement plz

* no comment either
parent 8dcf1ad8
......@@ -63,17 +63,23 @@ module.exports.listRoutes = function (app) {
module.exports.render = function (app, route, cb) {
var state = {}
state._experimental_prefetch = []
app.toString(route, state)
// TODO: replace with p-wait-all, once it knows how to handle an empty array.
Promise.all(state._experimental_prefetch)
.then(render, render)
return new Promise(function (resolve, reject) {
// First pass to populate prefetch
try {
app.toString(route, state)
} catch (err) {
return reject(err)
}
resolve(state._experimental_prefetch)
}).then(function (prefetches) {
return Promise.all(prefetches)
}).then(render).catch(cb)
function render () {
var body = app.toString(route, state)
delete state._experimental_prefetch // State needs to be serializable.
var res = { state: state }
if (body) res.body = body
res.body = app.toString(route, state)
delete res.state._experimental_prefetch // State needs to be serializable.
if (app.state.title) res.title = app.state.title
if (app.state.language) res.language = app.state.language
if (app.selector) res.selector = app.selector
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment