Skip to content

Commit 2397869

Browse files
bendikgoto-bus-stop
authored andcommitted
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
1 parent 8dcf1ad commit 2397869

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

ssr/choo.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,23 @@ module.exports.listRoutes = function (app) {
6363
module.exports.render = function (app, route, cb) {
6464
var state = {}
6565
state._experimental_prefetch = []
66-
app.toString(route, state)
6766

68-
// TODO: replace with p-wait-all, once it knows how to handle an empty array.
69-
Promise.all(state._experimental_prefetch)
70-
.then(render, render)
67+
return new Promise(function (resolve, reject) {
68+
// First pass to populate prefetch
69+
try {
70+
app.toString(route, state)
71+
} catch (err) {
72+
return reject(err)
73+
}
74+
resolve(state._experimental_prefetch)
75+
}).then(function (prefetches) {
76+
return Promise.all(prefetches)
77+
}).then(render).catch(cb)
7178

7279
function render () {
73-
var body = app.toString(route, state)
74-
delete state._experimental_prefetch // State needs to be serializable.
7580
var res = { state: state }
76-
if (body) res.body = body
81+
res.body = app.toString(route, state)
82+
delete res.state._experimental_prefetch // State needs to be serializable.
7783
if (app.state.title) res.title = app.state.title
7884
if (app.state.language) res.language = app.state.language
7985
if (app.selector) res.selector = app.selector

0 commit comments

Comments
 (0)