Skip to content

Instantly share code, notes, and snippets.

@vasilakisfil
Last active September 22, 2016 20:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vasilakisfil/f3380e4ff5fd6860bb15 to your computer and use it in GitHub Desktop.
Save vasilakisfil/f3380e4ff5fd6860bb15 to your computer and use it in GitHub Desktop.
How to show API errors in Ember
import Ember from 'ember';
import Notify from 'ember-notify';
export default Ember.Route.extend(ApplicationRouteMixin, {
actions: {
error: function (errorObject) {
if (errorObject) {
if (errorObject.status === 401) {
return this.transitionTo('login');
}
if (errorObject.errors) {
for(var error in errorObject.errors) {
Ember.Logger.debug(error);
Notify.warning(errorObject.errors[error]);
}
}
}
}
}
});
import Ember from 'ember';
import Notify from 'ember-notify';
export default Ember.ObjectController.extend({
actions: {
submitDetails: function() {
var _this = this;
this.get('model').save().then(
function(returnedModel) {
this.transitionToRoute('example', returnedModel);
},
function(errors) {
_this.send('error', errors);
}
);
/*
//ideally I would like to have just that
//let the error bubble up and catch it up in ApplicationRoute somehow!
submitDetails: function() {
this.get('model').save().then(function(returnedModel) {
this.transitionToRoute('example', returnedModel);
});
*/
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment