28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
export function adminErrorMessage(error: unknown): string {
|
|
if (!(error instanceof Error)) return "The administrative operation failed.";
|
|
const message = error.message;
|
|
const jsonStart = message.indexOf("{");
|
|
if (jsonStart >= 0) {
|
|
try {
|
|
const parsed = JSON.parse(message.slice(jsonStart)) as { detail?: unknown };
|
|
if (typeof parsed.detail === "string") return parsed.detail;
|
|
if (Array.isArray(parsed.detail)) {
|
|
return parsed.detail.map((item) => typeof item === "object" && item && "msg" in item ? String((item as { msg: unknown }).msg) : String(item)).join("; ");
|
|
}
|
|
} catch {
|
|
// Fall through to the original message.
|
|
}
|
|
}
|
|
return message;
|
|
}
|
|
|
|
export function formatDateTime(value?: string | null): string {
|
|
if (!value) return "Never";
|
|
const date = new Date(value);
|
|
return Number.isNaN(date.getTime()) ? value : date.toLocaleString();
|
|
}
|
|
|
|
export function joinLabels(values: Array<{ name: string }>): string {
|
|
return values.length ? values.map((value) => value.name).join(", ") : "—";
|
|
}
|