feat(web): show the error id on server failures and add the support info and report surfaces

This commit is contained in:
Marc-André Bombeck committed 2026-10-15 22:31:51 +02:00
1 parent 800bebd45c
commit f7386742b4
138 files changed
+1982 -318

No files matched your search

+3 -1
View File
@@ -4,6 +4,7 @@ import { useMemo } from "react";
import { StatTile } from "@/components/admin/_stat-tile";
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { toast } from "sonner";
import { showErrorToast } from "@/lib/errors/error-toast";
import { Cpu, Fingerprint, Globe, KeyRound } from "lucide-react";
import { Switch } from "@/components/ui/switch";
import { Badge } from "@/components/ui/badge";
@@ -297,10 +298,11 @@ export function useUpdateSettings() {
toast.success(t("common.saved"));
},
onError: (err) => {
toast.error(
showErrorToast(
err instanceof Error && err.message
? err.message
: t("admin.settingsSaveError"),
{ cause: err },
);
},
});
@@ -4,6 +4,7 @@ import { useState } from "react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { AlertTriangle, KeyRound, Loader2 } from "lucide-react";
import { toast } from "sonner";
import { showErrorToast } from "@/lib/errors/error-toast";
import { Badge } from "@/components/ui/badge";
import { SettingsCardActions } from "@/components/settings/_card-actions";
@@ -89,8 +90,9 @@ export function AiServerKeySection() {
toast.success(t("admin.aiServerKey.saved"));
},
onError: (error: unknown) => {
toast.error(
showErrorToast(
error instanceof Error ? error.message : t("admin.aiServerKey.error"),
{ cause: error },
);
},
});
+3 -1
View File
@@ -3,6 +3,7 @@
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { Sparkles } from "lucide-react";
import { toast } from "sonner";
import { showErrorToast } from "@/lib/errors/error-toast";
import { SettingsCard } from "@/components/settings/settings-card";
import { SettingsCardHeader } from "@/components/settings/_card-header";
@@ -104,10 +105,11 @@ function useUpdateAssistantFlags() {
toast.success(t("common.saved"));
},
onError: (err) => {
toast.error(
showErrorToast(
err instanceof Error && err.message
? err.message
: t("admin.settingsSaveError"),
{ cause: err },
);
client.invalidateQueries({
queryKey: queryKeys.adminAssistantFlags(),
+13 -6
View File
@@ -24,6 +24,7 @@ import {
} from "lucide-react";
import { useRef, useState, type ChangeEvent } from "react";
import { toast } from "sonner";
import { showErrorToast } from "@/lib/errors/error-toast";
import {
AlertDialog,
AlertDialogAction,
@@ -864,10 +865,11 @@ export function BackupsSection() {
}, 2000);
},
onError: (err) => {
toast.error(
showErrorToast(
err instanceof Error && err.message
? err.message
: t("admin.section.backups.runFailed"),
{ cause: err },
);
},
});
@@ -923,10 +925,11 @@ export function BackupsSection() {
},
onError: (err) => {
if (err instanceof ReproofCancelledError) return;
toast.error(
showErrorToast(
err instanceof Error && err.message
? err.message
: t("admin.section.backups.uploadFailed"),
{ cause: err },
);
},
onSettled: () => {
@@ -983,7 +986,7 @@ export function BackupsSection() {
void queryClient.invalidateQueries();
} else if (job.status === "failed") {
setRefusedSections(missingSectionsOf(job.failure));
toast.error(t("admin.section.backups.restoreFailed"));
showErrorToast(t("admin.section.backups.restoreFailed"));
}
}
}
@@ -1061,17 +1064,20 @@ export function BackupsSection() {
err instanceof ApiError &&
err.meta?.errorCode === "backup.restore.active"
) {
toast.error(t("admin.section.backups.restoreActive"));
showErrorToast(t("admin.section.backups.restoreActive"), {
cause: err,
});
void queryClient.invalidateQueries({
queryKey: queryKeys.adminBackupRestores(),
});
return;
}
setRefusedSections([]);
toast.error(
showErrorToast(
err instanceof Error && err.message
? err.message
: t("admin.section.backups.restoreFailed"),
{ cause: err },
);
},
});
@@ -1109,10 +1115,11 @@ export function BackupsSection() {
toast.success(t("admin.section.backups.downloadStarted"));
} catch (err) {
if (err instanceof ReproofCancelledError) return;
toast.error(
showErrorToast(
err instanceof Error && err.message
? err.message
: t("admin.section.backups.downloadFailed"),
{ cause: err },
);
} finally {
setDownloadingId(null);
@@ -19,6 +19,7 @@ import { useEffect, useState } from "react";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { Loader2, ShieldAlert, Sparkles, Trash2 } from "lucide-react";
import { toast } from "sonner";
import { showErrorToast } from "@/lib/errors/error-toast";
import { Badge } from "@/components/ui/badge";
import { SettingsInfoTile } from "@/components/settings/_info-tile";
@@ -75,8 +76,9 @@ export function CentralCodexSection() {
intervalSeconds: json.data.intervalSeconds,
});
} catch (err) {
toast.error(
showErrorToast(
err instanceof Error ? err.message : t("admin.centralCodex.error"),
{ cause: err },
);
setDevicePolling(false);
}
@@ -110,8 +112,9 @@ export function CentralCodexSection() {
if (!cancelled) setTimeout(tick, intervalMs);
} catch (err) {
if (cancelled) return;
toast.error(
showErrorToast(
err instanceof Error ? err.message : t("admin.centralCodex.error"),
{ cause: err },
);
setDeviceCode(null);
setDevicePolling(false);
@@ -142,8 +145,9 @@ export function CentralCodexSection() {
});
void invalidateKeys(queryClient, aiInputDependentKeys);
} catch (err) {
toast.error(
showErrorToast(
err instanceof Error ? err.message : t("admin.centralCodex.error"),
{ cause: err },
);
} finally {
setDisconnecting(false);
+5 -1
View File
@@ -23,6 +23,7 @@ import {
ShieldCheck,
} from "lucide-react";
import { toast } from "sonner";
import { showErrorToast } from "@/lib/errors/error-toast";
import {
AlertDialog,
AlertDialogAction,
@@ -125,7 +126,10 @@ export function EncryptionSection() {
});
},
onError: (err: Error) => {
toast.error(err.message || t("admin.section.encryption.rotateFailed"));
showErrorToast(
err.message || t("admin.section.encryption.rotateFailed"),
{ cause: err },
);
},
});
+3 -1
View File
@@ -4,6 +4,7 @@ import { useState } from "react";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { AlertTriangle, Loader2 } from "lucide-react";
import { toast } from "sonner";
import { showErrorToast } from "@/lib/errors/error-toast";
import { SettingsCard } from "@/components/settings/settings-card";
import { SettingsCardActions } from "@/components/settings/_card-actions";
import { SettingsCardHeader } from "@/components/settings/_card-header";
@@ -111,10 +112,11 @@ export function GlitchtipSection() {
});
},
onError: (error) => {
toast.error(
showErrorToast(
error instanceof Error
? error.message
: t("admin.monitoringTestFailed"),
{ cause: error },
);
void queryClient.invalidateQueries({
queryKey: queryKeys.adminSettings(),
@@ -30,6 +30,7 @@ import { useState } from "react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { Ban, Check, Copy, Loader2, Plus, Ticket, Users } from "lucide-react";
import { toast } from "sonner";
import { showErrorToast } from "@/lib/errors/error-toast";
import {
AlertDialog,
@@ -221,8 +222,8 @@ export function InviteTokensSection() {
toast.success(t("admin.invites.createdToast"));
queryClient.invalidateQueries({ queryKey: queryKeys.adminInvites() });
},
onError: () => {
toast.error(t("admin.invites.createError"));
onError: (failure) => {
showErrorToast(t("admin.invites.createError"), { cause: failure });
},
});
@@ -234,8 +235,8 @@ export function InviteTokensSection() {
toast.success(t("admin.invites.revokedToast"));
queryClient.invalidateQueries({ queryKey: queryKeys.adminInvites() });
},
onError: () => {
toast.error(t("admin.invites.revokeError"));
onError: (failure) => {
showErrorToast(t("admin.invites.revokeError"), { cause: failure });
},
});
@@ -245,8 +246,8 @@ export function InviteTokensSection() {
setCopied(true);
toast.success(t("admin.invites.copiedToast"));
window.setTimeout(() => setCopied(false), 2_000);
} catch {
toast.error(t("admin.invites.copyError"));
} catch (failure) {
showErrorToast(t("admin.invites.copyError"), { cause: failure });
}
}
+8 -3
View File
@@ -15,6 +15,7 @@ import { useState } from "react";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { KeyRound, Loader2 } from "lucide-react";
import { toast } from "sonner";
import { showErrorToast } from "@/lib/errors/error-toast";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
@@ -106,11 +107,13 @@ export function KeyBackupCard() {
},
onError: async (err: Error) => {
if (err instanceof ApiError && err.status === 409) {
toast.error(t("admin.keyBackup.stale"));
showErrorToast(t("admin.keyBackup.stale"), { cause: err });
await invalidate();
return;
}
toast.error(err.message || t("admin.keyBackup.confirmFailed"));
showErrorToast(err.message || t("admin.keyBackup.confirmFailed"), {
cause: err,
});
},
});
@@ -133,7 +136,9 @@ export function KeyBackupCard() {
},
onError: (err: Error) => {
setCheckResult(null);
toast.error(err.message || t("admin.keyBackup.checkFailed"));
showErrorToast(err.message || t("admin.keyBackup.checkFailed"), {
cause: err,
});
},
});
@@ -3,6 +3,7 @@
import { useMemo, useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { toast } from "sonner";
import { showErrorToast } from "@/lib/errors/error-toast";
import {
Check,
CheckCircle2,
@@ -112,8 +113,8 @@ export function LoginOverviewSection() {
window.setTimeout(() => {
setCopiedIp((current) => (current === id ? null : current));
}, 2_000);
} catch {
toast.error(t("admin.copyFailed"));
} catch (failure) {
showErrorToast(t("admin.copyFailed"), { cause: failure });
}
}
@@ -14,6 +14,7 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { Database, Loader2, Wrench } from "lucide-react";
import { toast } from "sonner";
import { showErrorToast } from "@/lib/errors/error-toast";
import { StatTile } from "@/components/admin/_stat-tile";
import { SettingsCardActions } from "@/components/settings/_card-actions";
@@ -92,7 +93,10 @@ export function MeasurementMaintenanceCard() {
});
},
onError: (err: Error) => {
toast.error(err.message || t("admin.section.maintenance.startFailed"));
showErrorToast(
err.message || t("admin.section.maintenance.startFailed"),
{ cause: err },
);
},
});
@@ -4,6 +4,7 @@ import Link from "next/link";
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import { ToggleLeft } from "lucide-react";
import { toast } from "sonner";
import { showErrorToast } from "@/lib/errors/error-toast";
import { SettingsCard } from "@/components/settings/settings-card";
import { SettingsCardHeader } from "@/components/settings/_card-header";
@@ -74,10 +75,11 @@ function useUpdateModuleAvailability() {
toast.success(t("common.saved"));
},
onError: (err) => {
toast.error(
showErrorToast(
err instanceof Error && err.message
? err.message
: t("admin.modules.saveError"),
{ cause: err },
);
client.invalidateQueries({
queryKey: queryKeys.adminModuleAvailability(),
+6 -3
View File
@@ -11,6 +11,7 @@ import {
XCircle,
} from "lucide-react";
import { toast } from "sonner";
import { showErrorToast } from "@/lib/errors/error-toast";
import { Badge } from "@/components/ui/badge";
import { SettingsCardActions } from "@/components/settings/_card-actions";
import { Button } from "@/components/ui/button";
@@ -144,7 +145,7 @@ export function RemindersSection() {
onSuccess: (data) => {
const failures = describeChannelTestFailures(data?.results ?? [], t);
if (failures.length > 0) {
toast.error(data?.message ?? t("admin.notificationTestFailed"), {
showErrorToast(data?.message ?? t("admin.notificationTestFailed"), {
description: (
<ul className="space-y-0.5">
{failures.map((line) => (
@@ -158,10 +159,11 @@ export function RemindersSection() {
}
},
onError: (error) => {
toast.error(
showErrorToast(
error instanceof Error
? error.message
: t("admin.notificationTestFailed"),
{ cause: error },
);
},
});
@@ -196,8 +198,9 @@ export function RemindersSection() {
toast.success(data?.message ?? t("admin.reminderCheckSuccess"));
},
onError: (error) => {
toast.error(
showErrorToast(
error instanceof Error ? error.message : t("admin.reminderCheckFailed"),
{ cause: error },
);
},
});
@@ -0,0 +1,128 @@
"use client";
import { useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { Copy, Download, LifeBuoy, Loader2 } from "lucide-react";
import { Button } from "@/components/ui/button";
import { SettingsCard } from "@/components/settings/settings-card";
import { SettingsCardHeader } from "@/components/settings/_card-header";
import { SettingsCardActions } from "@/components/settings/_card-actions";
import { apiGet } from "@/lib/api/api-fetch";
import { showErrorToast } from "@/lib/errors/error-toast";
import { useTranslations } from "@/lib/i18n/context";
import { queryKeys } from "@/lib/query-keys";
interface SupportReport {
generatedAt: string;
text: string;
}
/**
* Admin, System status: the redacted support report, with copy and download.
*
* The report is made on request, not on page load: it reads every account's
* connection health, which is work an operator only wants when filing a bug.
* Once made it is shown in full above the actions, so the operator reads what
* they are about to share.
*/
export function SupportReportCard() {
const { t } = useTranslations();
const [copied, setCopied] = useState(false);
const report = useQuery({
queryKey: queryKeys.adminSupportReport(),
queryFn: async () => apiGet<SupportReport>("/api/admin/support-report"),
enabled: false,
staleTime: 0,
gcTime: 5 * 60_000,
});
async function load(): Promise<SupportReport | null> {
const result = await report.refetch();
if (result.error || !result.data) {
showErrorToast(t("admin.supportReport.loadError"), {
cause: result.error,
});
return null;
}
return result.data;
}
async function copy() {
const data = await load();
if (!data) return;
try {
await navigator.clipboard.writeText(data.text);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch {
window.prompt(t("admin.supportReport.copy"), data.text);
}
}
async function download() {
const data = await load();
if (!data) return;
const blob = new Blob([data.text], { type: "text/plain;charset=utf-8" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = `healthlog-support-report-${data.generatedAt.slice(0, 10)}.txt`;
document.body.appendChild(link);
link.click();
link.remove();
setTimeout(() => URL.revokeObjectURL(url), 1000);
}
const busy = report.isFetching;
return (
<SettingsCard>
<SettingsCardHeader
icon={LifeBuoy}
title={t("admin.supportReport.title")}
description={t("admin.supportReport.description")}
/>
<p className="text-sm">{t("admin.supportReport.body")}</p>
{report.data && (
<pre
data-slot="support-report-text"
className="bg-muted/50 max-h-80 overflow-auto rounded-lg border p-3 font-mono text-xs whitespace-pre-wrap"
>
{report.data.text}
</pre>
)}
<SettingsCardActions>
<Button
variant="outline"
size="sm"
className="min-h-11 sm:min-h-9"
onClick={() => void copy()}
disabled={busy}
aria-live="polite"
>
{busy ? (
<Loader2
className="size-4 animate-spin motion-reduce:animate-none"
aria-hidden="true"
/>
) : (
<Copy className="size-4" aria-hidden="true" />
)}
{copied
? t("admin.supportReport.copied")
: t("admin.supportReport.copy")}
</Button>
<Button
size="sm"
className="min-h-11 sm:min-h-9"
onClick={() => void download()}
disabled={busy}
>
<Download className="size-4" aria-hidden="true" />
{t("admin.supportReport.download")}
</Button>
</SettingsCardActions>
</SettingsCard>
);
}
+3 -1
View File
@@ -4,6 +4,7 @@ import { useState } from "react";
import { useMutation } from "@tanstack/react-query";
import { Activity, Loader2 } from "lucide-react";
import { toast } from "sonner";
import { showErrorToast } from "@/lib/errors/error-toast";
import { SettingsCard } from "@/components/settings/settings-card";
import { SettingsCardActions } from "@/components/settings/_card-actions";
import { SettingsCardHeader } from "@/components/settings/_card-header";
@@ -50,10 +51,11 @@ export function UmamiSection() {
toast.success(message);
},
onError: (error) => {
toast.error(
showErrorToast(
error instanceof Error
? error.message
: t("admin.monitoringTestFailed"),
{ cause: error },
);
},
});
@@ -12,6 +12,7 @@ import {
Users,
} from "lucide-react";
import { toast } from "sonner";
import { showErrorToast } from "@/lib/errors/error-toast";
import { Badge } from "@/components/ui/badge";
import { SettingsCardActions } from "@/components/settings/_card-actions";
import { Button } from "@/components/ui/button";
@@ -99,10 +100,11 @@ export function UserManagementSection() {
toast.success(t("common.saved"));
},
onError: (err) => {
toast.error(
showErrorToast(
err instanceof Error && err.message
? err.message
: t("admin.settingsSaveError"),
{ cause: err },
);
},
});
@@ -144,10 +146,11 @@ export function UserManagementSection() {
setLogoutTarget(null);
},
onError: (err) => {
toast.error(
showErrorToast(
err instanceof Error && err.message
? err.message
: t("admin.section.users.forceLogoutFailed"),
{ cause: err },
);
},
});
@@ -3,6 +3,7 @@
import { useState } from "react";
import { useQueryClient } from "@tanstack/react-query";
import { toast } from "sonner";
import { showErrorToast } from "@/lib/errors/error-toast";
import { BellRing, KeyRound, Loader2 } from "lucide-react";
import { SettingsCard } from "@/components/settings/settings-card";
import { SettingsCardActions } from "@/components/settings/_card-actions";
@@ -96,7 +97,7 @@ export function WebPushVapidSection() {
}
if (!res.ok) {
toast.error(t("admin.webPushVapidGenerateFailed"));
showErrorToast(t("admin.webPushVapidGenerateFailed"), { cause: res });
return;
}
@@ -113,8 +114,8 @@ export function WebPushVapidSection() {
queryKey: queryKeys.adminSettings(),
});
toast.success(t("admin.webPushVapidGenerated"));
} catch {
toast.error(t("admin.webPushVapidGenerateFailed"));
} catch (failure) {
showErrorToast(t("admin.webPushVapidGenerateFailed"), { cause: failure });
} finally {
setGenerating(false);
}