From 48b2365a3b56b8a56bed7a77d2832ea51b617d6c Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 29 Oct 2022 21:31:30 +0300 Subject: Handle rendering errors --- vnext/server/middleware/renderer.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'vnext/server/middleware') 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 = '
'; const data = htmlData.split(marker); const propsData = `${marker}`; + let didError = false; const { pipe } = ReactDOMServer.renderToPipeableStream( , { 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); }); }; -- cgit v1.2.3