From 611e258d96b158c7ca86af2ea961a1da19bc9c2b Mon Sep 17 00:00:00 2001 From: Igor Loskutov Date: Wed, 3 Sep 2025 09:04:40 -0400 Subject: [PATCH] schema generator error type doc --- www/app/(app)/rooms/page.tsx | 12 +++++++++++- www/app/(app)/rooms/useRoomList.tsx | 11 +---------- www/app/lib/AuthProvider.tsx | 1 + www/app/lib/apiHooks.ts | 8 +++++++- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/www/app/(app)/rooms/page.tsx b/www/app/(app)/rooms/page.tsx index d79e878e..9dac87a2 100644 --- a/www/app/(app)/rooms/page.tsx +++ b/www/app/(app)/rooms/page.tsx @@ -92,7 +92,12 @@ export default function RoomsList() { ); const [isEditing, setIsEditing] = useState(false); const [editRoomId, setEditRoomId] = useState(null); - const { loading, response, refetch } = useRoomList(PaginationPage(1)); + const { + loading, + response, + refetch, + error: roomListError, + } = useRoomList(PaginationPage(1)); const [nameError, setNameError] = useState(""); const [linkCopied, setLinkCopied] = useState(""); const [selectedStreamId, setSelectedStreamId] = useState(null); @@ -114,6 +119,8 @@ export default function RoomsList() { error: detailedEditedRoomError, } = useRoomGet(editRoomId); + const error = roomListError || detailedEditedRoomError; + // room being edited, as fetched from the server const editedRoom: typeof roomInitialState | null = useMemo( () => @@ -359,6 +366,9 @@ export default function RoomsList() { ); + if (roomListError) + return
{`${roomListError.name}: ${roomListError.message}`}
; + return ( void; }; -type ValidationError = components["schemas"]["ValidationError"]; - -const formatValidationErrors = (errors: ValidationError[]) => { - return errors.map((error) => error.msg).join(", "); -}; - // Wrapper to maintain backward compatibility const useRoomList = (page: PaginationPage): RoomList => { const { data, isLoading, error, refetch } = useRoomsList(page); - return { response: data || null, loading: isLoading, error: error - ? new Error( - error.detail ? formatValidationErrors(error.detail) : undefined, - ) + ? new Error(error.detail ? JSON.stringify(error.detail) : undefined) : null, refetch, }; diff --git a/www/app/lib/AuthProvider.tsx b/www/app/lib/AuthProvider.tsx index 8ad083cf..71db8c0f 100644 --- a/www/app/lib/AuthProvider.tsx +++ b/www/app/lib/AuthProvider.tsx @@ -29,6 +29,7 @@ const AuthContext = createContext(undefined); export function AuthProvider({ children }: { children: React.ReactNode }) { const { data: session, status, update } = useNextAuthSession(); const customSession = session ? assertExtendedTokenAndUserId(session) : null; + console.log("customSessioncustomSession", customSession); const contextValue: AuthContextType = { ...(status === "loading" && !customSession diff --git a/www/app/lib/apiHooks.ts b/www/app/lib/apiHooks.ts index 2baa5a26..f14bc24c 100644 --- a/www/app/lib/apiHooks.ts +++ b/www/app/lib/apiHooks.ts @@ -3,9 +3,15 @@ import { $api } from "./apiClient"; import { useError } from "../(errors)/errorContext"; import { useQueryClient } from "@tanstack/react-query"; -import type { components, paths } from "../reflector-api"; +import type { components } from "../reflector-api"; import { useAuth } from "./AuthProvider"; +/* + * XXX error types returned from the hooks are not always correct; declared types are ValidationError but real type could be string or any other + * this is either a limitation or incorrect usage of Python json schema generator + * or, limitation or incorrect usage of .d type generator from json schema + * */ + const useAuthReady = () => { const auth = useAuth();