From 859ba1bef8a8e1d23468e6a5adbbf89683d59cb1 Mon Sep 17 00:00:00 2001 From: Sergey Tarasov Date: Fri, 19 Aug 2016 13:26:39 +0300 Subject: [PATCH] Pass-through JS error to client -- no catch in rendering (#521) * throws error on client * moved throw from handleError to clientStartup * modified message, updated js styling --- CHANGELOG.md | 2 ++ node_package/src/clientStartup.js | 8 +++----- node_package/src/handleError.js | 4 +++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77b4b6142..eda59f3ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com] - React on Rails now correctly parses single-digit version strings from package.json [#491](https://github.com/shakacode/react_on_rails/pull/491) by [samphilipd ](https://github.com/samphilipd ). - Fixed assets symlinking to correctly use filenames with spaces. Begining in [#510](https://github.com/shakacode/react_on_rails/pull/510), ending in [#513](https://github.com/shakacode/react_on_rails/pull/513) by [dzirtusss](https://github.com/dzirtusss) - Added authenticityToken() and authenticityHeaders() javascript helpers for easier use when working with CSRF protection tag generated by Rails [#517](https://github.com/shakacode/react_on_rails/pull/517) by [dzirtusss](https://github.com/dzirtusss) +- Updated JavaScript error handling on the client side from catching internally to passing through to the browser [#521](https://github.com/shakacode/react_on_rails/pull/521) by [dzirtusss](https://github.com/dzirtusss) + ## [6.0.5] - 2016-07-11 ##### Added diff --git a/node_package/src/clientStartup.js b/node_package/src/clientStartup.js index 0075bfb72..9a67ba8e9 100644 --- a/node_package/src/clientStartup.js +++ b/node_package/src/clientStartup.js @@ -78,11 +78,9 @@ You should return a React.Component always for the client side entry point.`); } } } catch (e) { - handleError({ - e, - name, - serverSide: false, - }); + e.message = `ReactOnRails encountered an error while rendering component: ${name}.` + + `Original message: ${e.message}`; + throw e; } } diff --git a/node_package/src/handleError.js b/node_package/src/handleError.js index 0c5f70b70..d0a465cce 100644 --- a/node_package/src/handleError.js +++ b/node_package/src/handleError.js @@ -35,7 +35,7 @@ component \'${name}\' is not a generator function.\n${lastLine}`; return msg; } -export default (options) => { +const handleError = (options) => { const { e, jsCode, serverSide } = options; console.error('Exception in rendering!'); @@ -64,3 +64,5 @@ ${e.stack}`; return ReactDOMServer.renderToString(reactElement); } }; + +export default handleError;