Client only collection for error handling display


#1

I would like to have a client only collection for showing errors with a tag {shown:false} which changes when error has been displayed. I have tried to create a client only collection using

Meteor.startup(function() {
            kmErrors = new Meteor.Collection(null);
            for ( var i = 0; i < 100; i++ ) {
                kmErrors.insert({ num: i });
            }
        }
);

But I keep getting the ReferenceError: kmErrors is not defined

Once I get over that hurdle, my intention is to call a server side function to insert data onto this client side collection. Is that even possible? I am using simple-schema and collections2 for validation of my collection calls (insert/update)

Any pointers on this?


#2

Take a look at https://atmospherejs.com/?q=error

Especially the ones with a description like “A pattern to display application errors to the user” are blanket copies of that exact same pattern from the discover meteor book.

The original one is the tmeasday:errors package.


#3

Thanks for the response @serkandurusoy, I actually have a minimal error logging package using a third party javascript library which I have managed to get running using Tracker and a mediator pattern.

My main concern is how to get a client only collection working and how I can query it on the client side as well as if it’s possible to send data from server to this client side collection (server calling client side methods).

If I can get that working I will be able to extrapolate that function to a wider set of things I intend to create.


#4

meteor-s-alert looks neat, let me read thru it’s code and revert. This should work :smile:


#5

Your original code snippet should work if it is in a client-only code block. Make sure it is not in a common (available to server) place. Also, change Meteor.Collection to Mongo.Collection.

Sending from server to client is best done using publications. In order to do that, Declare your client side collection with a name instead of null and publish to that.

Check out the room counts example from http://docs.meteor.com/#/full/meteor_publish to see how publishing arbitrary data to client-only collections work.


#6

I found where the problem was, my mistake. I have these code in a package which exports a namespace. I managed to get it working by adding the myAPP.kmErrors = new Mongo.Collection(null);

I am performing my validations on server side so basically I have to find a way to call my client side function. Adding another collection for that sync seems to beat the purpose for me so I have decided to have the validation.js file both on server and client side (This uses simple-schema and collections2 for validation). Am I breaking any security best practices rules here?


#7

You don’t need an extra collection to sync. Just use a name for your client side collection, instead of null, and publish your server side errors to that.