I’m not able to send the API errors in a format that Ember/EmberData (both v3.22.0) and is able to consume for model errors to display them in templates. I’m using RESTAdapter and RESTSerializer.
My product model looks like this:
export default class ProductModel extends Model {
@attr('string') name;
...
}
The expected default format is explained in the Documentation:
What I understand reading this, is:
// api response
{
errors: [
{
'attribute': 'name',
'message': 'This field cannot be blank.'
}
]
}
But I also tried many other formats. To see if the errors get properly processed by Ember, I console.log them in the catch block like this but still empty.
@action async save(product) {
try {
await product.save();
} catch(res) {
console.log('errors', product.get('errors')); // []
}
}
Hope someone could help me with that!