Use existing function to extract error message.

This commit is contained in:
Guo Xiang Tan 2015-09-17 10:55:06 +08:00
parent 086d31d53b
commit 25c7450ea7
1 changed files with 3 additions and 12 deletions

View File

@ -1,5 +1,6 @@
import ModalFunctionality from 'discourse/mixins/modal-functionality';
import DiscourseURL from 'discourse/lib/url';
import { extractError } from 'discourse/lib/ajax-error';
// Modal for editing / creating a category
export default Ember.Controller.extend(ModalFunctionality, {
@ -73,11 +74,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
model.setProperties({slug: result.category.slug, id: result.category.id });
DiscourseURL.redirectTo("/c/" + Discourse.Category.slugFor(model));
}).catch(function(error) {
if (error && error.responseText) {
self.flash($.parseJSON(error.responseText).errors[0], 'error');
} else {
self.flash(I18n.t('generic_error'), 'error');
}
self.flash(extractError(error), 'error');
self.set('saving', false);
});
},
@ -94,13 +91,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
self.send('closeModal');
DiscourseURL.redirectTo("/categories");
}, function(error){
if (error && error.responseText) {
self.flash($.parseJSON(error.responseText).errors[0]);
} else {
self.flash(I18n.t('generic_error'));
}
self.flash(extractError(error), 'error');
self.send('reopenModal');
self.displayErrors([I18n.t("category.delete_error")]);
self.set('deleting', false);