Meteor-Community-Packages / meteor-collection-hooks

Meteor Collection Hooks
https://atmospherejs.com/matb33/collection-hooks
MIT License
657 stars 92 forks source link

catching errors inside hooks for logging to papertrail #187

Open WayneUong opened 8 years ago

WayneUong commented 8 years ago

How do I catch exceptions? This code does not print out an error, where it should throw an exception as b is undefined.

Projects.after.insert(function (userId, doc) {
    try {
        a = b.c
    } catch (err) {
        console.log(err);
    }
});
lawrentiy commented 7 years ago

The best way - to realize catching into the package itself. Ive done so behavior in the fork and it saves my mind is case of chains of hooks. I dont know, why authors don`t implement it in package, m.b. because of optimization...

Or, do you call that code on server or client?

zimme commented 7 years ago

Wrap Projects.insert calls with try/catch and I believe that would catch errors throw inside its hooks.