Handling errors on the route/model
The latest build of Ember.
by Jeremy Gillick
HTML
<script src="http://builds.emberjs.com/handlebars-1.0.0.js"></script>
<script src="http://builds.emberjs.com/ember-latest.js"></script>
<script src="http://builds.emberjs.com/canary/ember-data.prod.js"></script>
<script type="text/x-handlebars" data-template-name="index">
<h1>Test errors on the ember route model</h1>
</script>
CSS
h1 { font-size: 1.6em; padding-bottom: 10px; }
h2 { font-size: 1.4em; }
section { margin: 7px 0; }
section .body { display: none; }
section .is-visible .body { display: block; }
JavaScript
App = Ember.Application.create({});
App.ApplicationAdapter = DS.RESTAdapter.extend({
host: 'https://google.com',
namespace: '/notapi/'
});
App.Post = DS.Model.extend({
title: DS.attr()
});
App.IndexRoute = Ember.Route.extend({
model: function(){
// Will always fail for XSS
//return $.get('http://google.com');
// Force immediate fail
//return Ember.RSVP.reject("FAIL");
return this.store.findQuery('post', {'foo':'bar'});
},
actions: {
error: function(reason) {
console.log('FAIL', reason.toString()); // "FAIL"
}
}
});