0

In my Controller call function like

Auth.register(credentials, config).then(function(registeredUser) {
        console.log(registeredUser);         
    }, function(error) {
        // Registration failed...
        console.log(error);

    });

It returns the JSON data response like

 {"errors":{"email":["has already been taken"]}}

On console the data object like

data    
Object { errors={...}}
errors  
Object { email=[1]}
email   
["has already been taken"]
0   
"has already been taken"

But how to access/get email error message to alert..?

8
  • 3
    Try data.errors.email[0] Commented Jun 9, 2015 at 5:06
  • Sorry it's not working ... Commented Jun 9, 2015 at 5:12
  • Why? jsfiddle.net/9b7xt12r Commented Jun 9, 2015 at 5:12
  • Error: data is not defined Commented Jun 9, 2015 at 5:13
  • ´data´ is a example, try console.log(error.errors.email[0]) Commented Jun 9, 2015 at 5:15

3 Answers 3

1

It's working using like this

console.log(error.data.errors.email);
Sign up to request clarification or add additional context in comments.

Comments

0

Try:

Auth.register(credentials, config).then(function(registeredUser){

    console.log(registeredUser);     

}, function(error) {
    // Registration failed...

    try{
        error = JSON.parse(error)
    }catch(e){}

    console.log(error.errors.email[0]);

});

Comments

0

Try this,

console.log(error.errors.email[0]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.