Hi all,
I’m using Meteor 1.2.1 with React and I’m struggling to figure out how to handle errors from subscriptions gracefully. I have a very simple example here where I want to render the Error component if the subscription fails. The behavior I’m observing is that if an error occurs in the subscription render() is never called. I am also unable to call setState() from getMeteorData() so I am lost as to how I could display a useful message to the user. Any feedback is welcome!!
getMeteorData: function() {
let error = null;
let itemHandle = Meteor.subscribe('ItemsPub', self.props.itemId, {
onStop: function(args) {
if (args.error) {
error = args.error;
}
}
} );
let item = Items.findOne({"itemId":self.props.itemId});
return {
error: error,
loading: !itemHandle.ready(),
item: item
};
},
render() {
if (this.data.error) return ( <Error message={this.data.error}/> );
if (this.data.loading) return (<LoadingSpinner/>);
return (
<div>Item: {this.data.item.title}</div>
);
},