Commit
Add deleteSession API wrapper
commit
feb6221
1 changed file with +8 and −0
modified client/src/api.ts +8 −0
| @@ -39,6 +39,14 @@export function getSession(id: string): Promise<Session> { | ||
| 39 | 39 | return requestJson<Session>(`${BASE}/sessions/${id}`) |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | +export async function deleteSession(id: string): Promise<void> { | |
| 43 | + const res = await fetch(`${BASE}/sessions/${id}`, { method: 'DELETE' }) | |
| 44 | + if (!res.ok) { | |
| 45 | + const body = (await res.json().catch(() => null)) as { error?: string } | null | |
| 46 | + throw new Error(body?.error ?? `request failed with status ${res.status}`) | |
| 47 | + } | |
| 48 | +} | |
| 49 | + | |
| 42 | 50 | export function submitAnswer(id: string, req: AnswerRequest): Promise<AnswerResponse> { |
| 43 | 51 | return requestJson<AnswerResponse>(`${BASE}/sessions/${id}/answer`, { |
| 44 | 52 | method: 'POST', |