javascriptnode.jsmongodbmeteormeteorite

how i catch and insert Meteor.Error alerts From Meteor.Methods in to a client side db?


i just writing a error notification panel in meteor, here i create a client side mongodb, but i cant push Meteor.Error message in to that client side db by throwError function, currently it's shows inside an alert box

collection/signup.js

signupDB = new Meteor.Collection('signup');

Meteor.methods({

    signupSubmit : function(postData) {

        var signinEmailExist = signinDB.findOne({
        email : postData.email
        });

        if (postData.email && signinEmailExist)
        throw new Meteor.Error(422, "exist in signinDB");

        var signupEmailExist = signupDB.findOne({
        email : postData.email
        });

        if (postData.email && signupEmailExist)
        throw new Meteor.Error(422, "exist in signupDB");       //    

        var user = _.extend(_.pick(postData, 'email', 'password'), {
            insert_time : new Date().getTime()      });

        var userId = signupDB.insert(user);

        return userId;

    }

});

client/error/error.js

errorDB = new Meteor.Collection(null);

throwError = function(data) {
    errorDB.insert({data: "in throwError", del: "N"})
}

errorDB.insert({data: "in signup", del: "N"}) code is working anywhere inside client folder

here throwError function can't called, but signupSubmit method errors shows in a alert box

is the problem of publication/subscription like thinks (not wrote for signup db) ?

how i catch and insert Meteor.Error alerts From Meteor.Methods in to a client side db ?

is there any other function like throwError to trap Meteor.Methods errors ?


Solution

  • How are you calling the method? You need to do something like:

    Meteor.call('signupSubmit', user, function(err) {
      errorDB.insert(err);
    });
    

    However, you seem to be implementing a custom, insecure authentication system. You shouldn't do this; Meteor has a great, secure built-in Accounts package. All you need to do is (on the client side):

    errors = new Meteor.Collection;
    
    Accounts.createUser({
      email: email,
      password: password
    }, function(err) {
      errors.insert(err);
    });
    

    The Accounts.createUser method automatically returns an error if the username/email is duplicated.