ff-stream-web

git clone git://archive.git.mtrnord.blog/MTRNord/ff-stream-web.git
Log | Files | Refs | README | LICENSE

commit 7d9421fc09f6e4249c601b7776df9a2a10cd11b5
parent a55d311492b82dc6db19f3100d0a1b0b214d8fb9
Author: Paweł Małolepszy <pawel.malolepszy@dictionary.com>
Date:   Thu,  2 Feb 2017 17:02:31 +0100

Adds error handler to `window` object.

Diffstat:
Msrc/client.js | 12++++++++++++
1 file changed, 12 insertions(+), 0 deletions(-)

diff --git a/src/client.js b/src/client.js @@ -176,6 +176,18 @@ async function onLocationChange(location) { history.listen(onLocationChange); onLocationChange(currentLocation); +// Handle errors that might happen after rendering +// Display the error in full-screen for development mode +// Fallback to console.error in production mode +window.addEventListener('error', (e) => { + console.error(e.error); // eslint-disable-line no-console + + if (process.env.NODE_ENV !== 'production') { + document.title = `Error: ${e.error.message}`; + ReactDOM.render(<ErrorReporter error={e.error} />, container); + } +}); + // Enable Hot Module Replacement (HMR) if (module.hot) { module.hot.accept('./routes', () => {