Type caught errors as unknown in the frontend

Replace `catch (e: any)` with `catch (e)` and read the message through a
new errorMessage() helper. ApiError.data gets a real type, and
useDismissingState's setter keeps one identity across renders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 11:10:00 +02:00
co-authored by Claude Opus 5.5
parent 9e8244bb71
commit 5024ab7241
55 changed files with 400 additions and 332 deletions
@@ -5,6 +5,7 @@ import { useAuth } from "@/hooks/useAuth";
import { apiFetch, API_BASE } from "@/lib/api";
import { useDismissingState } from "@/hooks/useDismissingState";
import { DatabaseBackup, Download } from "lucide-react";
import { errorMessage } from "@/lib/utils";
interface BackupEntry {
filename: string;
@@ -38,8 +39,8 @@ export function BackupsTab({ active }: { active: boolean }) {
]);
setBackups(list || []);
setRetainCount(allSettings?.backup_retain_count || "14");
} catch (e: any) {
setMessage({ type: "err", text: e?.message || "Failed to load backups" });
} catch (e) {
setMessage({ type: "err", text: errorMessage(e) || "Failed to load backups" });
} finally {
setLoading(false);
}
@@ -51,8 +52,8 @@ export function BackupsTab({ active }: { active: boolean }) {
try {
await apiFetch("/api/settings", { method: "PUT", authToken: token, body: { backup_retain_count: retainCount } });
setMessage({ type: "ok", text: "Retention setting saved." });
} catch (e: any) {
setMessage({ type: "err", text: e?.message || "Failed to save retention setting" });
} catch (e) {
setMessage({ type: "err", text: errorMessage(e) || "Failed to save retention setting" });
} finally {
setSavingRetain(false);
}
@@ -68,8 +69,8 @@ export function BackupsTab({ active }: { active: boolean }) {
const res = await apiFetch<{ filename: string }>("/api/backups/run", { method: "POST", authToken: token });
setMessage({ type: "ok", text: `Backup created: ${res.filename}` });
await load();
} catch (e: any) {
setMessage({ type: "err", text: e?.message || "Backup failed" });
} catch (e) {
setMessage({ type: "err", text: errorMessage(e) || "Backup failed" });
} finally {
setRunning(false);
}
@@ -5,6 +5,7 @@ import { useAuth } from "@/hooks/useAuth";
import { apiFetch } from "@/lib/api";
import { useDismissingState } from "@/hooks/useDismissingState";
import { Copy, CreditCard, KeyRound, Trash2, Webhook } from "lucide-react";
import { errorMessage } from "@/lib/utils";
type Source = "db" | "env" | "none";
@@ -99,9 +100,9 @@ export function YocoTab({ active }: { active: boolean }) {
const res = await apiFetch<{ webhooks: YocoWebhook[] }>("/api/yoco/webhooks", { authToken: token });
setHooks(res.webhooks || []);
setHooksError(null);
} catch (e: any) {
} catch (e) {
setHooks([]);
setHooksError(e?.message || "Could not load webhooks from Yoco");
setHooksError(errorMessage(e) || "Could not load webhooks from Yoco");
}
}, [token]);
@@ -114,8 +115,8 @@ export function YocoTab({ active }: { active: boolean }) {
setHookUrl((prev) => prev || c.webhookUrl);
if (c.secretKeySource !== "none") await loadHooks();
else { setHooks([]); setHooksError(null); }
} catch (e: any) {
setMessage({ type: "err", text: e?.message || "Failed to load Yoco settings" });
} catch (e) {
setMessage({ type: "err", text: errorMessage(e) || "Failed to load Yoco settings" });
} finally {
setLoading(false);
}
@@ -130,8 +131,8 @@ export function YocoTab({ active }: { active: boolean }) {
const text = await fn();
setMessage({ type: "ok", text });
await load();
} catch (e: any) {
setMessage({ type: "err", text: e?.message || "Something went wrong" });
} catch (e) {
setMessage({ type: "err", text: errorMessage(e) || "Something went wrong" });
} finally {
setBusy(null);
}