FIX: properly handle errors when creating a topic
This commit is contained in:
parent
0a41ec59e8
commit
d7b3f9bfe2
|
@ -234,7 +234,6 @@ export default Ember.ObjectController.extend(Presence, {
|
||||||
imageSizes: this.get('view').imageSizes(),
|
imageSizes: this.get('view').imageSizes(),
|
||||||
editReason: this.get("editReason")
|
editReason: this.get("editReason")
|
||||||
}).then(function(result) {
|
}).then(function(result) {
|
||||||
|
|
||||||
if (result.responseJson.action === "enqueued") {
|
if (result.responseJson.action === "enqueued") {
|
||||||
self.send('postWasEnqueued', result.responseJson);
|
self.send('postWasEnqueued', result.responseJson);
|
||||||
self.destroyDraft();
|
self.destroyDraft();
|
||||||
|
|
|
@ -7,20 +7,33 @@ function extractError(error) {
|
||||||
Ember.Logger.error(error);
|
Ember.Logger.error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
let parsedError;
|
if (error.jqXHR) {
|
||||||
if (error.responseText) {
|
error = error.jqXHR;
|
||||||
|
}
|
||||||
|
|
||||||
|
let parsedError, parsedJSON;
|
||||||
|
|
||||||
|
if (error.responseJSON) {
|
||||||
|
parsedJSON = error.responseJSON;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!parsedJSON && error.responseText) {
|
||||||
try {
|
try {
|
||||||
const parsedJSON = $.parseJSON(error.responseText);
|
parsedJSON = $.parseJSON(error.responseText);
|
||||||
if (parsedJSON.errors) {
|
|
||||||
parsedError = parsedJSON.errors[0];
|
|
||||||
} else if (parsedJSON.failed) {
|
|
||||||
parsedError = parsedJSON.message;
|
|
||||||
}
|
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
// in case the JSON doesn't parse
|
// in case the JSON doesn't parse
|
||||||
Ember.Logger.error(ex.stack);
|
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');
|
return parsedError || I18n.t('generic_error');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,11 +41,10 @@ export function throwAjaxError(undoCallback) {
|
||||||
return function(error) {
|
return function(error) {
|
||||||
// If we provided an `undo` callback
|
// If we provided an `undo` callback
|
||||||
if (undoCallback) { undoCallback(error); }
|
if (undoCallback) { undoCallback(error); }
|
||||||
|
|
||||||
throw extractError(error);
|
throw extractError(error);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function popupAjaxError(err) {
|
export function popupAjaxError(error) {
|
||||||
bootbox.alert(extractError(err));
|
bootbox.alert(extractError(error));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue