diff --git a/app/assets/javascripts/discourse/models/composer.js b/app/assets/javascripts/discourse/models/composer.js index 914b94ce1..09dbaabd8 100644 --- a/app/assets/javascripts/discourse/models/composer.js +++ b/app/assets/javascripts/discourse/models/composer.js @@ -310,11 +310,14 @@ Discourse.Composer = Discourse.Model.extend({ composer.set('topic.draft_sequence', savedPost.draft_sequence); } }, function(error) { - var errors; - errors = $.parseJSON(error.responseText).errors; - promise.reject(errors[0]); + var response = $.parseJSON(error.responseText); + if (response && response.errors) { + promise.reject(errors[0]); + } else { + promise.reject(Em.String.i18n('generic_error')); + } post.set('cooked', oldCooked); - return composer.set('composeState', OPEN); + composer.set('composeState', OPEN); }); }); }, diff --git a/app/assets/javascripts/discourse/models/post.js b/app/assets/javascripts/discourse/models/post.js index baf2f47ff..cfa7faa47 100755 --- a/app/assets/javascripts/discourse/models/post.js +++ b/app/assets/javascripts/discourse/models/post.js @@ -151,14 +151,16 @@ Discourse.Post = Discourse.Model.extend({ data: { post: { raw: this.get('raw') }, image_sizes: this.get('imageSizes') - }, - success: function(result) { - // If we received a category update, update it - if (result.category) Discourse.get('site').updateCategory(result.category); - return typeof complete === "function" ? complete(Discourse.Post.create(result.post)) : void 0; - }, - error: function(result) { return typeof error === "function" ? error(result) : void 0; } + } + }).then(function(result) { + // If we received a category update, update it + if (result.category) Discourse.get('site').updateCategory(result.category); + if (complete) complete(Discourse.Post.create(result.post)); + }, function(result) { + // Post failed to update + if (error) error(result); }); + } else { // We're saving a post @@ -178,13 +180,13 @@ Discourse.Post = Discourse.Model.extend({ return Discourse.ajax({ type: 'POST', url: Discourse.getURL("/posts"), - data: data, - success: function(result) { - return typeof complete === "function" ? complete(Discourse.Post.create(result)) : void 0; - }, - error: function(result) { - return typeof error === "function" ? error(result) : void 0; - } + data: data + }).then(function(result) { + // Post created + if (complete) complete(Discourse.Post.create(result)); + }, function(result) { + // Failed to create a post + if (error) error(result); }); } },