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) writeEarlyHints(event, link)
} }
const _rendered = await renderer.renderToString(ssrContext).catch((err) => { const _rendered = await renderer.renderToString(ssrContext).catch((error) => {
if (!ssrError) {
// Use explicitly thrown error in preference to subsequent rendering errors // Use explicitly thrown error in preference to subsequent rendering errors
throw ssrContext.payload?.error || err throw (!ssrError && ssrContext.payload?.error) || error
}
}) })
await ssrContext.nuxt?.hooks.callHook('app:rendered', { ssrContext }) await ssrContext.nuxt?.hooks.callHook('app:rendered', { ssrContext })
// Handle errors // Handle errors
if (!_rendered) {
return undefined!
}
if (ssrContext.payload?.error && !ssrError) { if (ssrContext.payload?.error && !ssrError) {
throw ssrContext.payload.error throw ssrContext.payload.error
} }