aboutsummaryrefslogtreecommitdiff
path: root/vnext/server
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2022-10-29 21:31:30 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:58 +0300
commit48b2365a3b56b8a56bed7a77d2832ea51b617d6c (patch)
tree452b9c474a3ce82af0018270205f062a2d585eb8 /vnext/server
parentdcc082891b1090c77b412d5139d8b70ed50bdb36 (diff)
Handle rendering errors
Diffstat (limited to 'vnext/server')
-rw-r--r--vnext/server/middleware/renderer.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/vnext/server/middleware/renderer.js b/vnext/server/middleware/renderer.js
index e7ed3337..f60aa23c 100644
--- a/vnext/server/middleware/renderer.js
+++ b/vnext/server/middleware/renderer.js
@@ -34,21 +34,28 @@ const serverRenderer = async (req, res, next) => {
const marker = '<div id="app">';
const data = htmlData.split(marker);
const propsData = `<script>window.__PROPS__="${Buffer.from(JSON.stringify(props)).toString('base64')}";</script>${marker}`;
+ let didError = false;
const { pipe } = ReactDOMServer.renderToPipeableStream(
<StaticRouter location={req.baseUrl} context={routerContext}>
<App {...props} />
</StaticRouter>
, {
onShellReady() {
+ res.statusCode = didError ? 500 : 200;
+ res.setHeader('Content-type', 'text/html');
+ res.write(data[0]);
+ res.write(propsData);
pipe(res, { end: false });
},
onAllReady() {
res.write(data[1]);
res.end();
+ },
+ onError(err) {
+ didError = true;
+ console.log(err);
}
});
- res.write(data[0]);
- res.write(propsData);
});
};