AOSSIE-Org / AOSSIE-Org/DebateAI
Issue: WebSocket error handling is brittle and silently failing in useDebateWS
- Langage dominant
- TypeScript
- Étoiles
- 84
- Forks
- 198
- Merge moyen
- 2 j 19 h
- PR mergées (30 j)
- 30
Description
### 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`
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Évaluation
Cette issue n'a pas encore été évaluée.