diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6 index c6de8fd9627..f3da08e9b5a 100644 --- a/app/assets/javascripts/discourse/controllers/composer.js.es6 +++ b/app/assets/javascripts/discourse/controllers/composer.js.es6 @@ -234,7 +234,6 @@ export default Ember.ObjectController.extend(Presence, { imageSizes: this.get('view').imageSizes(), editReason: this.get("editReason") }).then(function(result) { - if (result.responseJson.action === "enqueued") { self.send('postWasEnqueued', result.responseJson); self.destroyDraft(); diff --git a/app/assets/javascripts/discourse/lib/ajax-error.js.es6 b/app/assets/javascripts/discourse/lib/ajax-error.js.es6 index f1a34add676..567fc2e45c4 100644 --- a/app/assets/javascripts/discourse/lib/ajax-error.js.es6 +++ b/app/assets/javascripts/discourse/lib/ajax-error.js.es6 @@ -7,20 +7,33 @@ function extractError(error) { Ember.Logger.error(error); } - let parsedError; - if (error.responseText) { + if (error.jqXHR) { + error = error.jqXHR; + } + + let parsedError, parsedJSON; + + if (error.responseJSON) { + parsedJSON = error.responseJSON; + } + + if (!parsedJSON && error.responseText) { try { - const parsedJSON = $.parseJSON(error.responseText); - if (parsedJSON.errors) { - parsedError = parsedJSON.errors[0]; - } else if (parsedJSON.failed) { - parsedError = parsedJSON.message; - } + parsedJSON = $.parseJSON(error.responseText); } catch(ex) { // in case the JSON doesn't parse Ember.Logger.error(ex.stack); } } + + if (parsedJSON) { + if (parsedJSON.errors && parsedJSON.errors.length > 0) { + parsedError = parsedJSON.errors[0]; + } else if (parsedJSON.failed) { + parsedError = parsedJSON.message; + } + } + return parsedError || I18n.t('generic_error'); } @@ -28,11 +41,10 @@ export function throwAjaxError(undoCallback) { return function(error) { // If we provided an `undo` callback if (undoCallback) { undoCallback(error); } - throw extractError(error); }; } -export function popupAjaxError(err) { - bootbox.alert(extractError(err)); +export function popupAjaxError(error) { + bootbox.alert(extractError(error)); }