2

I have a problem Handling errors using JSON-API, I done all steps like wrote in documentation but it's doesn't works.

I have model:

 var user = this.get('store').createRecord('user', {
    'email': 'test@test.com',
    'name': 'Lorem ipsum',
    'password': '123',
  });

  user.save().then(function(){
    ...
  }).catch(function(data){
    console.log(user.get('errors'), data);
    // data is ErrorClass  with deserialize errors inside
  });

And API responce (422 Unprocessable Entity):

    {  
   "errors":[  
      {  
         "detail":"Email address must be between 6 and 128 characters in length",
         "source":{  
            "pointer":"/data/attributes/password"
         }
      }
   ]
   }

In this case isError flag is false, user.get('errors') -> empty

I also tried response with 500 Internal Server Error code

In this case isError flag is true (as expected) and error object contain in adapterError

So what I'm doing wrong or what try to check, thanks in advance

user1156168
  • 936
  • 13
  • 32

1 Answers1

1

As for the isError flag, it shouldn't be true if you got Validation error (the one that has 422 code). It's described in docs.

Your main problem is that you have a redundant forward slash in the beginning. So you have to change this "pointer":"/data/attributes/password" to this "pointer":"data/attributes/password"

After this change you'll be able to get the errors for this property through user.get('errors.password');

Hope it helps!