I have an ember 2.0 app that hooks up to an ASP Web API back-end. I need a way to display errors, and I know ember has built in error handling. I'm currently trying to use ember data InvalidError. I can't seem to figure out how this is supposed to work. This is my current setup
Custom adapter
export default DS.RESTAdapter.extend({
handleResponse: function(status, headers, payload){
if(status === 422 && payload.errors){
console.log('working');
return new DS.InvalidError(payload.errors);
}
return payload;
}
});
My route, which inherits from a "super route", but does not affect anything going on in here at the moment.
export default superRoute.extend({
model: function(params) {
return this.store.query('rollup', {itemID: params.itemID});
}
});
When I call the route I get this error
Error while processing route: rollup The adapter rejected the commit because it was invalid Error: The adapter rejected the commit because it was invalid
at new Error (native)
at Error.EmberError (http://localhost:4200/assets/vendor.js:25605:21)
at Error.ember$data$lib$adapters$errors$$AdapterError (http://localhost:4200/assets/vendor.js:64391:50)
at Error.ember$data$lib$adapters$errors$$InvalidError (http://localhost:4200/assets/vendor.js:64465:52)
at handleResponse (http://localhost:4200/assets/accounting-front.js:18:16)
at ember$data$lib$system$adapter$$default.extend.ajax.Ember.RSVP.Promise.hash.error (http://localhost:4200/assets/vendor.js:66084:33)
at jQuery.Callbacks.fire (http://localhost:4200/assets/vendor.js:3350:30)
at Object.jQuery.Callbacks.self.fireWith [as rejectWith] (http://localhost:4200/assets/vendor.js:3462:7)
at done (http://localhost:4200/assets/vendor.js:9518:14)
at XMLHttpRequest.jQuery.ajaxTransport.options.send.callback (http://localhost:4200/assets/vendor.js:9920:8)
I've been trying to get this to work using a number of examples I have found around here. I have got this to work by setting up my controller's model through the setupController hook instead of in the model hook but I would like to not do that.
Aucun commentaire:
Enregistrer un commentaire