Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions admin_panel/admin_panel/page/account_hub/account_hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,22 @@ function formatCurrency(cents, currency) {
return sym + (cents / 100).toFixed(2);
}

function formatApiErrors(errors) {
// Flash GraphQL mutations return validation failures as an array of
// { message } objects, not strings. String()-ing them (e.g. via
// Array.join) renders "[object Object]" — pull the message out of each.
if (!errors) return "";
const list = Array.isArray(errors) ? errors : [errors];
return list
.map((e) => {
if (typeof e === "string") return e;
if (e && typeof e === "object") return e.message || e.error || JSON.stringify(e);
return e == null ? "" : String(e);
})
.filter(Boolean)
.join(", ");
}

/* ─────────────────────────────────────────────
AccountHub Class
───────────────────────────────────────────── */
Expand Down Expand Up @@ -1391,9 +1407,7 @@ class AccountHub {
frappe.msgprint({
title: "Error",
indicator: "red",
message: Array.isArray(result.errors)
? result.errors.join(", ")
: result.errors,
message: formatApiErrors(result.errors),
});
} else {
frappe.show_alert(
Expand Down Expand Up @@ -1462,9 +1476,7 @@ class AccountHub {
frappe.msgprint({
title: "Error",
indicator: "red",
message: Array.isArray(result.errors)
? result.errors.join(", ")
: result.errors,
message: formatApiErrors(result.errors),
});
} else {
frappe.show_alert(
Expand Down Expand Up @@ -1532,9 +1544,7 @@ class AccountHub {
frappe.msgprint({
title: "Error",
indicator: "red",
message: Array.isArray(result.errors)
? result.errors.join(", ")
: result.errors,
message: formatApiErrors(result.errors),
});
} else {
frappe.show_alert(
Expand Down Expand Up @@ -1579,9 +1589,7 @@ class AccountHub {
frappe.msgprint({
title: "Error",
indicator: "red",
message: Array.isArray(result.errors)
? result.errors.join(", ")
: result.errors,
message: formatApiErrors(result.errors),
});
} else {
frappe.show_alert(
Expand Down Expand Up @@ -1620,9 +1628,7 @@ class AccountHub {
frappe.msgprint({
title: "Error",
indicator: "red",
message: Array.isArray(result.errors)
? result.errors.join(", ")
: result.errors,
message: formatApiErrors(result.errors),
});
} else {
frappe.show_alert(
Expand Down
Loading