Last active
September 22, 2016 20:18
-
-
Save vasilakisfil/f3380e4ff5fd6860bb15 to your computer and use it in GitHub Desktop.
How to show API errors in Ember
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | |
} | |
} | |
} | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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