While trying to handle server side errors in Ember application, I am unable to show the errors in templates. On record.save action the API returns errors as:
Hmm. It looks like you are creating the record⦠But you are not setting the model. You might need to do something like
this.set(āmodelā, user); ?
var user is contained within register function basically it doesnāt look like you are setting the model in the route. Iām not too sure but itās something to think about.
Thanks for the help. Directly setting the model didnāt give the results but I have done something like:
var route = this;
user.save().then(function(){
//handle success
},function(error){
var errors = user.get('errors');
route.set('_model.errors',errors);
});
In model I have to return the _model
_model:{},
model(){
return this.get(ā_modelā);
}
But the question is why do we need to set the model manually? Shouldnāt the model update/ reset itself when it gets error in response from the API as it happens in case of successful creation/updation of records?
There probably is a better, I donāt have the full picture to tell you lol. Maybe someone else can give some advice? mode()l is just a hook that feeds the controller the thing being returned, thatās one of the core responsibilities of route.
You can look into observes and notifypropertychange methods. Here is an example I found. Also, maybe you might need to rethink a different approach? I mean if it works, it works right?