FIX: properly handle errors when creating a topic

This commit is contained in:
Régis Hanol 2015-05-12 22:02:06 +02:00
parent 0a41ec59e8
commit d7b3f9bfe2
2 changed files with 23 additions and 12 deletions

View File

@ -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();

View File

@ -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));
}