refactor: narrow WebSocket exception handling

Replace bare Exception catch with specific exception types:
- json.JSONDecodeError for invalid JSON
- TypeError, KeyError, ValueError for malformed messages
- OSError for I/O errors

Addresses REFACTORING.md item about narrowing WebSocket error handling.
This commit is contained in:
GitHub Copilot
2026-01-24 10:24:00 +00:00
parent 33da0e335c
commit f2996c2d9e
+6 -2
View File
@@ -381,8 +381,12 @@ class LocalServer:
session_created = await self._dispatch_ws_message(
envelope, route_key, ws, session_created
)
except Exception as e:
log.error("Error processing WebSocket message: %s", e)
except json.JSONDecodeError as e:
log.warning("Invalid JSON in WebSocket message: %s", e)
except (TypeError, KeyError, ValueError) as e:
log.warning("Malformed WebSocket message: %s", e)
except OSError as e:
log.error("I/O error processing WebSocket message: %s", e)
elif msg.type == WSMsgType.ERROR:
log.error("WebSocket connection error for route %s", route_key)
break