mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:44:49 +08:00
FIX: simplify display of multiple AJAX errors (#18763)
Our dialog service doesn't accept HTML by default and we shouldn't include HTML in the error message string. And given that the Ajax error handler is called in multiple contexts, it's tricky to properly support line breaks via either HTML or `\n` so we are opting for plain text in AJAX error messages.
This commit is contained in:
parent
e120c94236
commit
0297c79cbe
|
@ -33,8 +33,14 @@ export function extractError(error, defaultMessage) {
|
|||
}
|
||||
|
||||
if (parsedJSON) {
|
||||
if (parsedJSON.errors && parsedJSON.errors.length > 0) {
|
||||
parsedError = parsedJSON.errors.join("<br>");
|
||||
if (parsedJSON.errors?.length > 1) {
|
||||
parsedError = I18n.t("multiple_errors", {
|
||||
errors: parsedJSON.errors.map((e, i) => `${i + 1}) ${e}`).join(" "),
|
||||
});
|
||||
} else if (parsedJSON.errors?.length > 0) {
|
||||
parsedError = I18n.t("generic_error_with_reason", {
|
||||
error: parsedJSON.errors[0],
|
||||
});
|
||||
} else if (parsedJSON.error) {
|
||||
parsedError = parsedJSON.error;
|
||||
} else if (parsedJSON.message) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import I18n from "I18n";
|
||||
import {
|
||||
acceptance,
|
||||
count,
|
||||
|
@ -166,7 +167,9 @@ acceptance("Category Edit", function (needs) {
|
|||
|
||||
assert.strictEqual(
|
||||
query(".dialog-body").textContent.trim(),
|
||||
"duplicate email"
|
||||
I18n.t("generic_error_with_reason", {
|
||||
error: "duplicate email",
|
||||
})
|
||||
);
|
||||
|
||||
await click(".dialog-footer .btn-primary");
|
||||
|
|
|
@ -363,8 +363,10 @@ acceptance(
|
|||
|
||||
assert.strictEqual(
|
||||
query(".dialog-body").innerText.trim(),
|
||||
"There was an issue with the SMTP credentials provided, check the username and password and try again.",
|
||||
"shows a dialogue with the error message from the server"
|
||||
I18n.t("generic_error_with_reason", {
|
||||
error:
|
||||
"There was an issue with the SMTP credentials provided, check the username and password and try again.",
|
||||
})
|
||||
);
|
||||
await click(".dialog-footer .btn-primary");
|
||||
});
|
||||
|
|
|
@ -257,6 +257,7 @@ en:
|
|||
delete: "Delete"
|
||||
generic_error: "Sorry, an error has occurred."
|
||||
generic_error_with_reason: "An error occurred: %{error}"
|
||||
multiple_errors: "Multiple errors occurred: %{errors}"
|
||||
sign_up: "Sign Up"
|
||||
log_in: "Log In"
|
||||
age: "Age"
|
||||
|
|
Loading…
Reference in New Issue
Block a user