mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
schema generator error type doc
This commit is contained in:
@@ -92,7 +92,12 @@ export default function RoomsList() {
|
|||||||
);
|
);
|
||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
const [editRoomId, setEditRoomId] = useState<string | null>(null);
|
const [editRoomId, setEditRoomId] = useState<string | null>(null);
|
||||||
const { loading, response, refetch } = useRoomList(PaginationPage(1));
|
const {
|
||||||
|
loading,
|
||||||
|
response,
|
||||||
|
refetch,
|
||||||
|
error: roomListError,
|
||||||
|
} = useRoomList(PaginationPage(1));
|
||||||
const [nameError, setNameError] = useState("");
|
const [nameError, setNameError] = useState("");
|
||||||
const [linkCopied, setLinkCopied] = useState("");
|
const [linkCopied, setLinkCopied] = useState("");
|
||||||
const [selectedStreamId, setSelectedStreamId] = useState<number | null>(null);
|
const [selectedStreamId, setSelectedStreamId] = useState<number | null>(null);
|
||||||
@@ -114,6 +119,8 @@ export default function RoomsList() {
|
|||||||
error: detailedEditedRoomError,
|
error: detailedEditedRoomError,
|
||||||
} = useRoomGet(editRoomId);
|
} = useRoomGet(editRoomId);
|
||||||
|
|
||||||
|
const error = roomListError || detailedEditedRoomError;
|
||||||
|
|
||||||
// room being edited, as fetched from the server
|
// room being edited, as fetched from the server
|
||||||
const editedRoom: typeof roomInitialState | null = useMemo(
|
const editedRoom: typeof roomInitialState | null = useMemo(
|
||||||
() =>
|
() =>
|
||||||
@@ -359,6 +366,9 @@ export default function RoomsList() {
|
|||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (roomListError)
|
||||||
|
return <div>{`${roomListError.name}: ${roomListError.message}`}</div>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex
|
<Flex
|
||||||
flexDir="column"
|
flexDir="column"
|
||||||
|
|||||||
@@ -11,23 +11,14 @@ type RoomList = {
|
|||||||
refetch: () => void;
|
refetch: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ValidationError = components["schemas"]["ValidationError"];
|
|
||||||
|
|
||||||
const formatValidationErrors = (errors: ValidationError[]) => {
|
|
||||||
return errors.map((error) => error.msg).join(", ");
|
|
||||||
};
|
|
||||||
|
|
||||||
// Wrapper to maintain backward compatibility
|
// Wrapper to maintain backward compatibility
|
||||||
const useRoomList = (page: PaginationPage): RoomList => {
|
const useRoomList = (page: PaginationPage): RoomList => {
|
||||||
const { data, isLoading, error, refetch } = useRoomsList(page);
|
const { data, isLoading, error, refetch } = useRoomsList(page);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
response: data || null,
|
response: data || null,
|
||||||
loading: isLoading,
|
loading: isLoading,
|
||||||
error: error
|
error: error
|
||||||
? new Error(
|
? new Error(error.detail ? JSON.stringify(error.detail) : undefined)
|
||||||
error.detail ? formatValidationErrors(error.detail) : undefined,
|
|
||||||
)
|
|
||||||
: null,
|
: null,
|
||||||
refetch,
|
refetch,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
|||||||
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||||
const { data: session, status, update } = useNextAuthSession();
|
const { data: session, status, update } = useNextAuthSession();
|
||||||
const customSession = session ? assertExtendedTokenAndUserId(session) : null;
|
const customSession = session ? assertExtendedTokenAndUserId(session) : null;
|
||||||
|
console.log("customSessioncustomSession", customSession);
|
||||||
|
|
||||||
const contextValue: AuthContextType = {
|
const contextValue: AuthContextType = {
|
||||||
...(status === "loading" && !customSession
|
...(status === "loading" && !customSession
|
||||||
|
|||||||
@@ -3,9 +3,15 @@
|
|||||||
import { $api } from "./apiClient";
|
import { $api } from "./apiClient";
|
||||||
import { useError } from "../(errors)/errorContext";
|
import { useError } from "../(errors)/errorContext";
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
import type { components, paths } from "../reflector-api";
|
import type { components } from "../reflector-api";
|
||||||
import { useAuth } from "./AuthProvider";
|
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 useAuthReady = () => {
|
||||||
const auth = useAuth();
|
const auth = useAuth();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user