fix(nuxt): preserve render errors (#8884)

* fix(nuxt): preserve render errors

* simplify logic
This commit is contained in:
pooya parsa 2022-11-10 13:28:20 +01:00 committed by GitHub
parent 0ff4ebe808
commit 83b5c09090
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -172,18 +172,13 @@ export default defineRenderHandler(async (event) => {
writeEarlyHints(event, link)
}
const _rendered = await renderer.renderToString(ssrContext).catch((err) => {
if (!ssrError) {
// Use explicitly thrown error in preference to subsequent rendering errors
throw ssrContext.payload?.error || err
}
const _rendered = await renderer.renderToString(ssrContext).catch((error) => {
// Use explicitly thrown error in preference to subsequent rendering errors
throw (!ssrError && ssrContext.payload?.error) || error
})
await ssrContext.nuxt?.hooks.callHook('app:rendered', { ssrContext })
// Handle errors
if (!_rendered) {
return undefined!
}
if (ssrContext.payload?.error && !ssrError) {
throw ssrContext.payload.error
}