mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 04:42:55 +08:00
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(),
|
||||
editReason: this.get("editReason")
|
||||
}).then(function(result) {
|
||||
|
||||
if (result.responseJson.action === "enqueued") {
|
||||
self.send('postWasEnqueued', result.responseJson);
|
||||
self.destroyDraft();
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user