Skip to content

Commit 1c47cd7

Browse files
committed
fix: improve error handling and type usage in practice session hooks
1 parent 7d7ca37 commit 1c47cd7

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

frontend/src/data/localDB/practiceSessions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { PracticeCardResponse } from '@/client/types.gen'
22
import { v4 as uuidv4 } from 'uuid'
33
import { type LocalPracticeSession, db } from '../../db/flashcardsDB'
4-
import type { LocalPracticeCard } from '../../db/flashcardsDB'
4+
import type { LocalCard, LocalPracticeCard } from '../../db/flashcardsDB'
55

66
export const getLocalPracticeSessions = async (
77
collectionId: string,
@@ -53,7 +53,7 @@ async function createPracticeSession(
5353
return newSession
5454
}
5555

56-
async function createPracticeCardsForSession(sessionId: string, cards: any[]) {
56+
async function createPracticeCardsForSession(sessionId: string, cards: LocalCard[]) {
5757
const practiceCards: LocalPracticeCard[] = cards.map((card) => ({
5858
id: uuidv4(),
5959
sessionId,

frontend/src/hooks/usePracticeSession.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ export function usePracticeSession(collectionId: string) {
6060
isFlipped: false,
6161
}))
6262
}
63-
} catch (err: any) {
64-
setError(err.message || 'Failed to start session')
63+
} catch (err: unknown) {
64+
console.error(err)
65+
setError('Failed to start session')
6566
} finally {
6667
setIsLoading(false)
6768
startingRef.current = false
@@ -95,8 +96,9 @@ export function usePracticeSession(collectionId: string) {
9596
isFlipped: false,
9697
}
9798
})
98-
} catch (err: any) {
99-
setError(err.message || 'Failed to submit answer')
99+
} catch (err: unknown) {
100+
console.error(err)
101+
setError('Failed to submit answer')
100102
} finally {
101103
setIsLoading(false)
102104
}

0 commit comments

Comments
 (0)