Skip to content

Commit

Permalink
Add much better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
arunoda committed Mar 21, 2016
1 parent 2fcf999 commit 486df0c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
16 changes: 14 additions & 2 deletions dist/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ var Area = function Area(_ref) {
};

function renderArea() {
if (data.error) {
var _area = _react2.default.createElement(Area, { error: data.error });
_reactDom2.default.render(_area, rootEl);
return;
}

var main = _react2.default.createElement(
'p',
null,
Expand All @@ -74,11 +80,17 @@ function renderArea() {
if (paper) {
var block = data.papers[data.selectedPaper][data.selectedBlock];
if (block) {
main = block();
try {
main = block();
} catch (ex) {
data.error = ex;
renderArea();
return;
}
}
}

var area = _react2.default.createElement(Area, { main: main, error: data.error });
var area = _react2.default.createElement(Area, { main: main });
_reactDom2.default.render(area, rootEl);
}

Expand Down
2 changes: 1 addition & 1 deletion dist/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var webpack = require('webpack');

module.exports = {
devtool: 'cheap-module-eval-source-map',
entry: ['webpack-hot-middleware/client', './paper.js'],
entry: ['stack-source-map/register', 'webpack-hot-middleware/client', './.paper.js'],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
Expand Down
16 changes: 14 additions & 2 deletions load.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,28 @@ const Area = ({main, error}) => (
);

function renderArea() {
if (data.error) {
const area = <Area error={data.error} />;
ReactDOM.render(area, rootEl);
return;
}

let main = (<p>There is no blocks yet!</p>);
const paper = data.papers[data.selectedPaper];
if (paper) {
const block = data.papers[data.selectedPaper][data.selectedBlock];
if (block) {
main = block();
try {
main = block();
} catch(ex) {
data.error = ex;
renderArea();
return;
}
}
}

const area = <Area main={main} error={data.error}/>;
const area = <Area main={main} />;
ReactDOM.render(
area,
rootEl
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
"prepublish": ". ./scripts/prepublish.sh"
},
"dependencies": {
"ud": "^3.0.1",
"babel-runtime": "^6.3.14",
"babel-core": "^6.3.15",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-runtime": "^6.3.14",
"expect": "^1.6.0",
"express": "^4.13.3",
"node-libs-browser": "^0.5.2",
"redbox-react": "^1.2.2",
"stack-source-map": "^1.0.4",
"ud": "^3.0.1",
"webpack": "^1.9.11",
"webpack-dev-middleware": "^1.2.0",
"webpack-hot-middleware": "^2.2.0"
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var webpack = require('webpack');
module.exports = {
devtool: 'cheap-module-eval-source-map',
entry: [
'stack-source-map/register',
'webpack-hot-middleware/client',
'./.paper.js'
],
Expand Down

0 comments on commit 486df0c

Please sign in to comment.