AOSSIE-Org / AOSSIE-Org/DebateAI

Issue: WebSocket error handling is brittle and silently failing in useDebateWS

Aperta
#309 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
84
Fork
198
Merge medio
2g 19h
PR unite (30g)
30

Descrizione

### Problem

The WebSocket message handler in `frontend/src/hooks/useDebateWS.ts` had brittle error handling and previously contained empty `catch` blocks, which could silently swallow failures. This made debugging difficult and degraded user experience during connectivity issues.

Beyond the empty catch block, the existing implementation also had several reliability gaps, including:

* Silent failure modes during message parsing
* Potential console spamming on repeated failures
* Unclear reconnection behavior
* No distinction between normal vs abnormal WebSocket closure
* Risky cleanup logic on component unmount
* No protection against malformed or empty messages

---

### Expected Behavior

WebSocket failures should:

* Be clearly logged with meaningful context
* Avoid flooding logs or UI with repeated errors
* Attempt reconnection with controlled backoff
* Treat normal WebSocket closure (code 1000) as non-error
* Clean up safely when the component unmounts
* Gracefully handle malformed or empty messages

---

### Proposed Fix

Refactor **`useDebateWS.ts`** to include:

* Centralized `handleError` with throttling
* Exponential backoff retry logic with a maximum cap
* Clear handling of normal vs abnormal closures
* Defensive message parsing (reject empty messages)
* Safer WebSocket cleanup using `try/finally`
* Reset of error state on successful messages
* Automatic reconnection attempts on failure

---

### File Affected

* `frontend/src/hooks/useDebateWS.ts`

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.