24-Apr-2014 by Allison McMillan

Read Time: Approx. 1 minute

Errors in Ember

Most recently, I had to add a back button to a 404 page. I know, sounds simple, and it should be simple, but it was actually a little more complex than I thought which led me to learning about errors in Ember.

When originally looking in the codebase for where this change would need to happen, I found the ember template which simply said {{status}} {{statusText}} and a ember routes files that didn’t have anything in it except the standard code. I couldn’t figure out where the info being passed into the 404 was coming from and what made most sense for changing it.

When it comes down to it, the answer is actually pretty simple. Ember data has an automatic error route. In this case, we were looking in the user route. In this route, there is a model hook sets up a promise. this.store.find always returns a promise.

If the promise is returned from the model hook or in other words filled with user data, then the path completes and you arrives at the correct node in the user path. However, if the promise isn’t returned or is rejected, then you get thrown into the error route. Ember always waits for a promise to be fulfilled and if it isn’t, you are led to an entire default error state.

The ember guide gives a pretty good explanation and walk through of what happens to get to these error substates here: http://emberjs.com/guides/routing/loading-and-error-substates/

Ready to chat?

Join my mailing list

* indicates required

Set up a free call

phone icon