I’m aware of the subscription onError() callback, but this plays very poorly with stuff like React/createContainer – or maybe I’m just too stupid to make it work.
Any working examples or pointers would be nice, and I think that the guide should at least mention this stuff.
EDIT:
Just to clarify, my main problem is combining the React createContainer pattern with Meteor’s error handling. I can’t seem to find any good examples of this.
See my post below for example code.
Thanks for the link, @robfallows, that’s a good article!
Unfortunately it doesn’t address the issue of actually showing the error to the user.
Problem is, by the time the subscription onStop callback is fired, the view has already rendered (or failed due to lack of data).
Example:
const ViewContainer = createContainer(({params, location}) => {
const {_id} = params;
const {query} = location;
const token = query && query.token;
const subscription_handle = Meteor.subscribe('view_data', _id, token, {
onStop(error) {
if (error) {
// error comes back with info from the publication:
// 1) token is invalid
// 2) token is expired
// 3) _id is non-existent.
// I want to show this info in the view, but we have already rendered at this point.
}
}
});
const data = data_collection.findOne({_id});
return {
loading: !subscription_handle.ready(),
data
};
}, View);
Things I’ve tried:
Async/await syntax: Not immediately useful, since the subscription callback is wrapped in this weird object structure. I struggled for a bit down this road, but gave up.
ReactiveVar: This seemed like a pragmatic approach, but as soon as ReactiveVar got into the mix, the View component was re-rendered in an endless loop, crashing the browser.