better bundle renderer error handling

This commit is contained in:
Evan You 2016-06-26 11:50:14 -04:00
parent 5854f0f781
commit 9344bd7a52
2 changed files with 7 additions and 5 deletions

View File

@ -8,12 +8,16 @@ export function createBundleRendererCreator (createRenderer) {
renderToString: (context, cb) => {
runInVm(code, context).then(app => {
renderer.renderToString(app, cb)
})
}).catch(cb)
},
renderToStream: (context) => {
const res = new PassThrough()
runInVm(code, context).then(app => {
renderer.renderToStream(app).pipe(res)
}).catch(err => {
process.nextTick(() => {
res.emit('error', err)
})
})
return res
}

View File

@ -30,8 +30,6 @@ export default function runInVm (code, _context) {
const res = Object.prototype.hasOwnProperty.call(m.exports, 'default')
? m.exports.default
: m
if (typeof res.then !== 'function') {
throw new Error('SSR bundle should export a Promise.')
}
return res
// ensure returning a Promise
return Promise.resolve(res)
}