Skip to content

Commit 9b56362

Browse files
Abort if the session is rejected by the server
1 parent 82d93fd commit 9b56362

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/replit_river/error_schema.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
# ERROR_CODE_UNKNOWN is the code for the RiverUnknownError
2121
ERROR_CODE_UNKNOWN = "UNKNOWN"
2222

23+
# SESSION_STATE_MISMATCH is the code when the remote server rejects the session's state
24+
ERROR_CODE_SESSION_STATE_MISMATCH = "SESSION_STATE_MISMATCH"
25+
2326

2427
class RiverError(BaseModel):
2528
"""Error message from the server."""

src/replit_river/v2/session.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
)
3434
from replit_river.error_schema import (
3535
ERROR_CODE_CANCEL,
36+
ERROR_CODE_SESSION_STATE_MISMATCH,
3637
ERROR_CODE_STREAM_CLOSED,
3738
ERROR_HANDSHAKE,
3839
RiverError,
@@ -314,6 +315,8 @@ async def websocket_closed_callback() -> None:
314315
"river client get handshake response : %r", handshake_response
315316
) # noqa: E501
316317
if not handshake_response.status.ok:
318+
if handshake_response.status.code == ERROR_CODE_SESSION_STATE_MISMATCH:
319+
await self.close()
317320
raise RiverException(
318321
ERROR_HANDSHAKE,
319322
f"Handshake failed with code {handshake_response.status.code}: " # noqa: E501

0 commit comments

Comments
 (0)