Commit
Handle debate control failures
commit
2eab966
1 changed file with +14 and −2
modified src/components/debate/new-debate.tsx +14 −2
| @@ -207,7 +207,13 @@export function NewDebate({ | ||
| 207 | 207 | const cancelDebateRun = async () => { |
| 208 | 208 | if (!view.debateId) return; |
| 209 | 209 | try { |
| 210 | - await fetch(`/api/debates/${view.debateId}/cancel`, { method: 'POST' }); | |
| 210 | + const response = await fetch(`/api/debates/${view.debateId}/cancel`, { method: 'POST' }); | |
| 211 | + if (!response.ok) throw new Error('Cancel request failed'); | |
| 212 | + const result = (await response.json()) as { ok: boolean }; | |
| 213 | + if (!result.ok) { | |
| 214 | + toast.message('The roundtable is no longer running'); | |
| 215 | + return; | |
| 216 | + } | |
| 211 | 217 | toast.message('Cancelling the roundtable...'); |
| 212 | 218 | } catch { |
| 213 | 219 | toast.error('Could not cancel'); |
| @@ -217,7 +223,13 @@export function NewDebate({ | ||
| 217 | 223 | const concludeNow = async () => { |
| 218 | 224 | if (!view.debateId) return; |
| 219 | 225 | try { |
| 220 | - await fetch(`/api/debates/${view.debateId}/gavel`, { method: 'POST' }); | |
| 226 | + const response = await fetch(`/api/debates/${view.debateId}/gavel`, { method: 'POST' }); | |
| 227 | + if (!response.ok) throw new Error('Verdict request failed'); | |
| 228 | + const result = (await response.json()) as { ok: boolean }; | |
| 229 | + if (!result.ok) { | |
| 230 | + toast.message('The roundtable is no longer running'); | |
| 231 | + return; | |
| 232 | + } | |
| 221 | 233 | toast.message('Preparing a verdict from the opinions completed so far'); |
| 222 | 234 | } catch { |
| 223 | 235 | toast.error('Could not prepare the verdict'); |