I periodically call .refresh()
on my route as I am not using Ember data but instead rely on RSVP.hash
.
This allows me pretend that my application is autoreloading and works fine until the backend goes down and a failure occurs.
This causes an exception to be propagated to the frontend and makes the frontend enter an error state.
How do I use the old model before a reload if the reload fails? I have tried using a try/catch on the .refresh()
call but this does not appear to make a difference.
Thanks!
correct method is .refresh
. Please refer Route - 4.6 - Ember API Documentation
Thanks Elisha, sorry that was my mistake. I meant refresh()
and opposed to reload()
. However, this issue still stands with refresh()
.
One possible approach would be:
- implement
beforeModel()
hook and store current model as data
in transition. Refer Ember - 4.6 - Ember API Documentation
- implement
error
action for handling error events, and in reset the model
from transition object.
Refer Loading / Error Substates - Routing - Ember Guides
Thanks Elisha, super helpful. A quick followup: does beforeModel
have access to the model with the promises already resolved? For instance, if I do transition.data = this.model
, I would only get access to the model method and I don’t believe I can just call this.model()
at that point in the lifecycle.
model
property is set in route’s controller after successful resolution of the model from model()
hook.
so, your route code would be like:
beforeModel(transition) {
transition.data = this.get('controller').get('model');
},
model() {
//return promise
},
actions : {
error : function(error, transition) {
//set controller model = transition.data
}
}