881b409ebc
* feat: improve plugin failure handling and extension list UX * fix: address plugin review comments * fix: clear stale reload feedback on failed plugin reload * fix: refine extension i18n and uninstall flow * fix: refresh extension list after install failure * feat: add random plugin visibility controls in market * refactor: extract extension helpers and simplify uninstall flow * refactor: improve failed plugin diagnostics and uninstall flow * refactor: streamline extension uninstall flow * fix: harden failed plugin install tracking and cleanup * refactor: simplify extension flows and remove unused timed message * fix: improve failed uninstall idempotency and extension error handling * refactor: unify extension install-uninstall orchestration
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
const INVALID_ERROR_STRINGS = new Set(["[object Object]", "undefined", "null", ""]);
|
|
|
|
const pickResponseMessage = (responseData) => {
|
|
if (typeof responseData === "string") {
|
|
return responseData.trim();
|
|
}
|
|
if (!responseData || typeof responseData !== "object") {
|
|
return "";
|
|
}
|
|
|
|
const keys = ["message", "error", "detail", "details", "msg"];
|
|
for (const key of keys) {
|
|
const value = responseData[key];
|
|
if (typeof value === "string" && value.trim()) {
|
|
return value.trim();
|
|
}
|
|
}
|
|
return "";
|
|
};
|
|
|
|
export const resolveErrorMessage = (err, fallbackMessage = "") => {
|
|
if (typeof err === "string") {
|
|
return err.trim() || fallbackMessage;
|
|
}
|
|
if (typeof err === "number" || typeof err === "boolean") {
|
|
return String(err);
|
|
}
|
|
|
|
const fromResponse =
|
|
pickResponseMessage(err?.response?.data) ||
|
|
(typeof err?.response?.statusText === "string"
|
|
? err.response.statusText.trim()
|
|
: "");
|
|
const fromError =
|
|
typeof err?.message === "string" ? err.message.trim() : "";
|
|
|
|
let fromString = "";
|
|
if (typeof err?.toString === "function") {
|
|
const value = err.toString().trim();
|
|
fromString = INVALID_ERROR_STRINGS.has(value) ? "" : value;
|
|
}
|
|
|
|
return fromResponse || fromError || fromString || fallbackMessage;
|
|
};
|