diff --git a/frontend/src/components/UserSessionsOverview/AppSessionsList.tsx b/frontend/src/components/UserSessionsOverview/AppSessionsList.tsx index bcf8f426..9684d435 100644 --- a/frontend/src/components/UserSessionsOverview/AppSessionsList.tsx +++ b/frontend/src/components/UserSessionsOverview/AppSessionsList.tsx @@ -110,6 +110,11 @@ const paginationFamily = atomFamily((userId: string) => { return paginationAtom; }); +// A type-safe way to ensure we've handled all session types +const unknownSessionType = (type: never): never => { + throw new Error(`Unknown session type: ${type}`); +}; + const AppSessionsList: React.FC<{ userId: string }> = ({ userId }) => { const [pending, startTransition] = useTransition(); const result = useAtomValue(appSessionListFamily(userId)); @@ -131,7 +136,8 @@ const AppSessionsList: React.FC<{ userId: string }> = ({ userId }) => {
Apps
{appSessions.edges.map((session) => { - switch (session.node.__typename) { + const type = session.node.__typename; + switch (type) { case "Oauth2Session": return ( @@ -141,7 +147,7 @@ const AppSessionsList: React.FC<{ userId: string }> = ({ userId }) => { ); default: - throw new Error("Unexpected session type."); + unknownSessionType(type); } })} { return [route, redirecting]; }; +// A type-safe way to ensure we've handled all routes +const unknownRoute = (route: never): never => { + throw new Error(`Invalid route: ${JSON.stringify(route)}`); +}; + const Router: React.FC = () => { const [route, redirecting] = useRouteWithRedirect(); @@ -73,6 +78,8 @@ const Router: React.FC = () => { return ; case "unknown": return <>Unknown route {JSON.stringify(route.segments)}; + default: + unknownRoute(route); } };