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
@@ -8,6 +8,7 @@ import { isValidZAPhone } from "@/lib/phone";
import { useDismissingState } from "@/hooks/useDismissingState";
import { TwoFactorChallenge, TwoFactorMethod } from "@/lib/auth";
import { User, Lock, ShieldAlert, ShieldCheck, ShieldOff, Trash2, Clock, LogIn, KeyRound, RotateCcw } from "lucide-react";
import { errorMessage } from "@/lib/utils";
type ActivityEvent = { id: string; type: "login" | "password_changed" | "password_reset" | "two_factor_enabled" | "two_factor_disabled"; device: string | null; createdAt: string };
@@ -67,8 +68,8 @@ export default function UserProfilePage() {
// Backend returns a refreshed token — save it so the session stays valid
if (res?.token) updateToken(res.token);
setProfileMsg({ type: "ok", text: "Profile updated." });
} catch (e: any) {
setProfileMsg({ type: "err", text: e?.message || "Failed to update profile." });
} catch (e) {
setProfileMsg({ type: "err", text: errorMessage(e) || "Failed to update profile." });
} finally {
setSavingProfile(false);
}
@@ -106,8 +107,8 @@ export default function UserProfilePage() {
setConfirmPassword("");
setPwMsg({ type: "ok", text: "Password changed." });
loadActivity();
} catch (e: any) {
setPwMsg({ type: "err", text: e?.message || "Failed to change password." });
} catch (e) {
setPwMsg({ type: "err", text: errorMessage(e) || "Failed to change password." });
} finally {
setSavingPw(false);
}
@@ -131,8 +132,8 @@ export default function UserProfilePage() {
// save the freshly issued one so this device stays signed in.
if (res?.token) updateToken(res.token);
setRevokeMsg({ type: "ok", text: res?.message || "All other sessions signed out." });
} catch (e: any) {
setRevokeMsg({ type: "err", text: e?.message || "Failed to revoke sessions." });
} catch (e) {
setRevokeMsg({ type: "err", text: errorMessage(e) || "Failed to revoke sessions." });
} finally {
setRevoking(false);
}
@@ -203,8 +204,8 @@ export default function UserProfilePage() {
setTfCode("");
setTfPassword("");
setTfStep("code");
} catch (e: any) {
setTfMsg({ type: "err", text: e?.message || "Failed to send a verification code." });
} catch (e) {
setTfMsg({ type: "err", text: errorMessage(e) || "Failed to send a verification code." });
} finally {
setTfBusy(false);
}
@@ -227,8 +228,8 @@ export default function UserProfilePage() {
resetTwoFactorForm();
setTfMsg({ type: "ok", text: wasEnabled ? `Codes will now be sent by ${TWO_FACTOR_METHOD_LABEL[res.twoFactorMethod]}.` : "Two-factor authentication is on." });
loadActivity();
} catch (e: any) {
setTfMsg({ type: "err", text: e?.message || "Failed to verify the code." });
} catch (e) {
setTfMsg({ type: "err", text: errorMessage(e) || "Failed to verify the code." });
} finally {
setTfBusy(false);
}
@@ -249,8 +250,8 @@ export default function UserProfilePage() {
resetTwoFactorForm();
setTfMsg({ type: "ok", text: "Two-factor authentication is off." });
loadActivity();
} catch (e: any) {
setTfMsg({ type: "err", text: e?.message || "Failed to turn off two-factor authentication." });
} catch (e) {
setTfMsg({ type: "err", text: errorMessage(e) || "Failed to turn off two-factor authentication." });
} finally {
setTfBusy(false);
}
@@ -277,8 +278,8 @@ export default function UserProfilePage() {
setCloseMsg({ type: "ok", text: res?.message || "Account closed." });
// Slight delay so the user can read the message, then log out
setTimeout(() => logout(), 2500);
} catch (e: any) {
setCloseMsg({ type: "err", text: e?.message || "Failed to close account." });
} catch (e) {
setCloseMsg({ type: "err", text: errorMessage(e) || "Failed to close account." });
} finally {
setClosing(false);
}