Reputation: 675
I'm trying to handle server errors in an Ember application.
I'm running the following code in ember app:
customization.save().catch(function (error) {
console.log(error);
console.log(customization.get('errors'));
console.log(customization.get('errors.length'));
});
And my server is answering 422 status with the following json in payload:
{
"errors":[
{
"code":"app.customization.validationError.duplicateCustomizationName",
"detail":"a customization with same name already exists",
"source":{
"pointer":"customization/name"
}
}
]
}
The error is an InvalidError
, but customization.get('errors.length')
is always 0.
I'm using a DS.RESTAdapter along with DS.RESTSerializer in Ember 2.4.5 with Ember DATA 2.4.0.
What am I missing ?
Thanks
Upvotes: 0
Views: 42
Reputation: 675
Ok, I finally figured it out. The path in source.pointer
MUST be in JSONAPI style even if you're not using DS.JSONAPIAdapter.
Sending this:
...
"pointer":"data/attributes/name"
...
Solves this issue.
I thought the path in pointer referred to the path of the field in the actual JSON corresponding to the model, but that's apparently wrong.
Upvotes: 0