Sarfraz Ahmad
Sarfraz Ahmad

Reputation: 1439

show the appropriate Error Message to user from Meteor call

I am working with Meteorjs First time. In my application I am trying to Register a use. For this I am making a meteor call. Which returns me error if it is unsuccessful or success if user is registered successfully. My problem is when Someone try to register a user with a previously registered id meteor call returns error message that user name is already exists.this is my meteor call

var acct = {"email": email, "full_name": full_name, roles: roles}
var id = Meteor.call("register_staff", acct, function (error, result) {
if (error) {
     console.log(error)
     FlashMessages.sendError(" This email address is already registered")
} 
else {
       $("#user_creator_dialog").modal('hide');
       FlashMessages.sendSuccess("User Successesfully Created and Password Mailed")
     }
  }); 

if i do

 console.log(error)  

it shows me a Key value pair

Error: Username is already exists.
But when I try to get the key by using dot(.) notation like
console.log(error.Error)

it gives undefined

. my question is how can i access this error object key. before this i worked with javascript and jquery where dot notation works perfectly. I think in meteor there may be some other way to access this key.

Upvotes: 0

Views: 1044

Answers (1)

Jeremy S.
Jeremy S.

Reputation: 4639

If your Meteor method is throwing a new Meteor.Error the keys will include error, errorType, message, reason, and details. "Error" is the object but not one of the keys so "error.Error" in your callback will return undefined.

Try error.reason or error.message and see if that does it. It depends what is being returned from the method.

Upvotes: 1

Related Questions