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': '[email protected]',
    '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

1

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

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.