mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 03:33:39 +08:00
DEV: Allow HTML errors whenever a popup is generated (#20989)
Follow-up-to: 6bbf832400
This commit is contained in:
parent
5c2c1bf9a7
commit
355b44472b
|
@ -245,16 +245,9 @@ export default class AdminUserIndexController extends Controller.extend(
|
||||||
this.router.transitionTo("second-factor-auth", {
|
this.router.transitionTo("second-factor-auth", {
|
||||||
queryParams: { nonce },
|
queryParams: { nonce },
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
const htmlMessage = error.jqXHR?.responseJSON.html_message;
|
|
||||||
if (htmlMessage) {
|
|
||||||
this.dialog.alert({
|
|
||||||
message: htmlSafe(error.jqXHR?.responseJSON.error),
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
popupAjaxError(error);
|
popupAjaxError(error);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import { getOwner } from "discourse-common/lib/get-owner";
|
import { getOwner } from "discourse-common/lib/get-owner";
|
||||||
|
import { htmlSafe } from "@ember/template";
|
||||||
|
|
||||||
export function extractError(error, defaultMessage) {
|
function extractErrorInfo(error, defaultMessage) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error(error.stack);
|
console.error(error.stack);
|
||||||
|
@ -16,7 +17,9 @@ export function extractError(error, defaultMessage) {
|
||||||
error = error.jqXHR;
|
error = error.jqXHR;
|
||||||
}
|
}
|
||||||
|
|
||||||
let parsedError, parsedJSON;
|
let html = false,
|
||||||
|
parsedError,
|
||||||
|
parsedJSON;
|
||||||
|
|
||||||
if (error.responseJSON) {
|
if (error.responseJSON) {
|
||||||
parsedJSON = error.responseJSON;
|
parsedJSON = error.responseJSON;
|
||||||
|
@ -33,6 +36,10 @@ export function extractError(error, defaultMessage) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parsedJSON) {
|
if (parsedJSON) {
|
||||||
|
if (parsedJSON.html_message) {
|
||||||
|
html = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (parsedJSON.errors?.length > 1) {
|
if (parsedJSON.errors?.length > 1) {
|
||||||
parsedError = I18n.t("multiple_errors", {
|
parsedError = I18n.t("multiple_errors", {
|
||||||
errors: parsedJSON.errors.map((e, i) => `${i + 1}) ${e}`).join(" "),
|
errors: parsedJSON.errors.map((e, i) => `${i + 1}) ${e}`).join(" "),
|
||||||
|
@ -56,7 +63,14 @@ export function extractError(error, defaultMessage) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsedError || defaultMessage || I18n.t("generic_error");
|
return {
|
||||||
|
html,
|
||||||
|
message: parsedError || defaultMessage || I18n.t("generic_error"),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function extractError(error, defaultMessage) {
|
||||||
|
return extractErrorInfo(error, defaultMessage).message;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function throwAjaxError(undoCallback) {
|
export function throwAjaxError(undoCallback) {
|
||||||
|
@ -71,5 +85,11 @@ export function throwAjaxError(undoCallback) {
|
||||||
|
|
||||||
export function popupAjaxError(error) {
|
export function popupAjaxError(error) {
|
||||||
const dialog = getOwner(this).lookup("service:dialog");
|
const dialog = getOwner(this).lookup("service:dialog");
|
||||||
dialog.alert(extractError(error));
|
const errorInfo = extractErrorInfo(error);
|
||||||
|
|
||||||
|
if (errorInfo.html) {
|
||||||
|
dialog.alert({ message: htmlSafe(errorInfo.message) });
|
||||||
|
} else {
|
||||||
|
dialog.alert(errorInfo.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user