Skip to content

Commit 72c0a2a

Browse files
committed
feat: use schema parsing to confirm contents instead of casting it
1 parent 90b6abc commit 72c0a2a

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

apps/web/src/hooks/useFindSession.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import type { Session } from '@opendatacapture/schemas/session';
1+
import { type Session, $Session } from '@opendatacapture/schemas/session';
22
import axios from 'axios';
33

44
export const sessionInfo = async (sessionId: string): Promise<null | Session> => {
55
try {
66
const response = await axios.get(`/v1/sessions/${sessionId}`);
7-
return response.data ? (response.data as Session) : null;
7+
const parsedResult = $Session.safeParse(response.data);
8+
return parsedResult.success ? parsedResult.data : null;
89
} catch (error) {
910
console.error('Error fetching session:', error);
1011
throw error;

0 commit comments

Comments
 (0)