Skip to content

A platform for community discussion. Free, open, simple.

FIX: simplify display of multiple AJAX errors (#18763)

Penar Musaraj0297c79cbec2
diff --git a/app/assets/javascripts/discourse/app/lib/ajax-error.js b/app/assets/javascripts/discourse/app/lib/ajax-error.js
index 55a9a808335..cf93622a8cb 100644
--- a/app/assets/javascripts/discourse/app/lib/ajax-error.js
+++ b/app/assets/javascripts/discourse/app/lib/ajax-error.js
@@ -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) {
diff --git a/app/assets/javascripts/discourse/tests/acceptance/category-edit-test.js b/app/assets/javascripts/discourse/tests/acceptance/category-edit-test.js
index 5042f2c6141..9f777d5877b 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/category-edit-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/category-edit-test.js
@@ -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");
diff --git a/app/assets/javascripts/discourse/tests/acceptance/group-manage-email-settings-test.js b/app/assets/javascripts/discourse/tests/acceptance/group-manage-email-settings-test.js
index 9fb65779816..e7eaf493bcd 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/group-manage-email-settings-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/group-manage-email-settings-test.js
@@ -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");
});
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 7ac6707db41..f8da524387b 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -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"