-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
meteor server side method throwing not catched by callback in client #559
Comments
It should be: Post.extend({
meteorMethods: {
addModerator(id) {
// this error is undefined in the callback parameter.
throw new Meteor.Error('blabla', 'because blabla');
}
}
}); |
Yes. :D thought of everything but that. I'm sorry about it. |
I've just checked and I'm 100% sure that it works, so you're probably doing something wrong. Create reproduction repository. |
Same problem here I resolve by a warping the call on try catch
Not ideal but it works |
I do have the same type of problem... On the client:
On the server:
I do get the callback response Whatever the Am I missing something obvious? Thanks! |
@davidsavoie1 create reproduction repository |
@lukejagodzinski Here it is!. It's the first time a create a repo on Github for debugging, so tell me if there's anything missing! In my previous post, I wrote that the class definition is on the server, but that's incorrect... It's actually defined in the In the repo, everything is directly in the |
@davidsavoie1 the repository is ok. However, I see that there is a problem with lack of the |
@davidsavoie1 I'm trying to fix an issue that I've encountered when working with your reproduction repository and I've noticed that apparently there is some issue in Meteor. As when testing such a code in the browser console: Meteor.methods({test() { throw new Meteor.Error("error"); }});
Meteor.call("test", (err) => { console.log(err); }); I get the following output:
It says that there is not Another test shows the same result: Meteor.methods({test() { return "test" }});
Meteor.call("test", (err, result) => { console.log(err, result); }); Output:
So what's the solution? Do not use |
@lukejagodzinski OK, I get what you mean... I've adopted wrong pattterns because the last project I've done with Astronomy was a client only one. That's why I've declared everything in the client only. I've modified the code in the repo to ensure that the collection is defined both on the server and the client by importing the class in both I'm really sorry if there's some fundamental concept I don't grasp here that has nothing to do with Astronomy, but your help is very much appreciated... |
@davidsavoie1 update Astronomy version to |
@davidsavoie1 btw. thanks for the reproduction! It helped fix one more issue :) |
Ah great! I'm really glad to know that I do understand what I'm doing after all! 😆 Thanks to you! |
@lukejagodzinski I just tried the repo code again with version 2.5.5 of Astronomy and I think there's still an issue (or again, maybe it's my understanding). I don't seem to catch and handle a thrown error even when using a callback. The error is considered Class definitionconst Test = Class.create({
name: 'Test',
collection: new Mongo.Collection('tests'),
fields: {
/* Fields */
},
events: {
beforeSave(e) {
throw new Meteor.Error('save-error', 'Could not save!');
},
},
helpers: {
helper() {
throw new Meteor.Error('helper-error', 'because blabla');
},
},
meteorMethods: {
failMethod() {
throw new Meteor.Error('failMethod-error', 'because blabla');
},
successMethod() {
return true;
},
},
}); Tests on the clientconst test1 = new Test();
/* No error */
test1.successMethod((err, res) => {
console.log('From sucessMethod', { err, res });
});
/* Caught */
test1.save((err, res) => {
console.log('From save', { err, res });
});
/* Uncaught */
test1.failMethod((err, res) => {
console.log('From failMethod', { err, res });
});
/* Uncaught */
test1.helper((err, res) => {
console.log('From helper', { err, res });
}); The |
I added another test to see if I get the same kind of problem with regular Meteor Methods and I don't. Meteor.methods({
myMeteorMethod() {
throw new Meteor.Error('myMeteorMethod-error', 'Blablabla');
},
});
/* Caught */
Meteor.call('myMeteorMethod', (err, res) => {
console.log('From myMeteorMethod', { err, res });
}); The error gets caught even with a directly thrown error. That's the behavior I'm expecting. |
Helpers do not take a callback function as the last argument. After my fix in 2.5.5 you can use Meteor methods safely on the client only collections, so what I said previously is no longer true. You don't have to use helpers. Helpers are actually designed for things similar to helpers in Blaze templates. And yes there is still a bug I haven't noticed yesterday. I will fix it later today. It will be fixed in 2.5.6. |
@davidsavoie1 fixed in 2.5.6 |
@lukejagodzinski You're the best! 😉 Thanks for the quick responses, I'll be enjoying Astronomy for a while in the coming weeks! And you're absolutely right about helpers not using error callbacks, I had overlooked this detail. And it's great that Meteor Methods can now be used with local collections. It'll be much clearer that way! Dziękuję bardzo |
@davidsavoie1 you're welcome :) Hehe :) |
I've defined a server side meteor method in a class.
I throw a meteor error but the callback in the client side is not catching it.
The text was updated successfully, but these errors were encountered: