[SOLVED] Passing Server Error to Client

Hi there,

I was thinking to pass server side errors to my client side (browser) and show a nice dialogue for debugging purpose. Anyone has any idea how could I do it? emmmm…

You can return/throw errors on server side methods, then retrieve them from the client using Session.

Meteor.call('foo', function (err, res) {
    Session.set('err', err);
1 Like

Cool. Thanks for the tips. :smile:

What I have done is this, I saw it on a tute somewhere a long the way when learning…

You can create a client only collection for notifications (eg. called Notifications). It’s a reactive data source that’s easily manipulated.
Have anything in that collection display to the client in a modal or just a div at the top of your page.

Just throw a Notifications.insert({message: error}) whenever there is an error, and when the user dismisses the error it deletes it from that collection. Since its client only, the collection doesn’t need to sync with the server and nothing needs to be published.

1 Like

Indeed. I believe it was introduced in ‘Discover Meteor’ book. But now the problem is: I would like to throw error from ‘server’ to ‘client’. But your way can indeed works too, by using a collection! Just insert the error and let it auto publish to the user. Thanks for the idea. :smile:

1 Like

Ohhh sorry, now i suddenly realised, session cannot be used in ‘server’ side. I will proceed with @cstrat 's options. Thanks. :smiley:

In @hellstad’s suggestion, the Session call is in the Meteor.call call back which is on the Client side, triggering to a Server.method which returns an error. However your client would need to trigger that via the Meteor.call first… so it sounds like you’re wanting to send notifications that are not necessarily triggered by a client action. In which case a collection would probably be best!

Yup. I am using collection now. :smiley:

I’ve been looking for this as well.
The reason you can’t throw Error from server to client is that server doesn’t know to which client to send the error.
But when you call a method from client, server receives connection.id and thus can determine to which client to send the error.

1 Like