client: map WebSocket close reason to error code in _on_ws_closed

Godot discards buffered data packets when the close frame arrives, so the
JSON error sent by RejectAsync is never received. Map known server close
reasons (auth_failed, auth_required) from the close frame's reason field
to AUTH_FAILED / AUTH_REQUIRED so Auth.gd's logout+navigate logic fires
correctly instead of treating every rejection as a transient DISCONNECTED.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-01 20:46:48 -05:00
co-authored by Claude Happy
parent 5d4f0c3745
commit fa5beb104c
+17 -1
View File
@@ -169,11 +169,27 @@ func _on_ws_closed() -> void:
if debug_log_packets:
print("[Net] Closed code=%d reason=%s" % [code, reason])
# Map server-encoded close reasons to error codes so callers (e.g. Auth.gd)
# can take the right action. Godot discards buffered data packets when the
# close frame arrives, so the reason field is the only signal we have.
var error_code: String
var error_msg: String
match reason:
"auth_failed":
error_code = "AUTH_FAILED"
error_msg = "Session expired or revoked."
"auth_required":
error_code = "AUTH_REQUIRED"
error_msg = "Authentication required."
_:
error_code = "DISCONNECTED"
error_msg = "Connection lost."
# Fail all pending requests immediately.
for seq in _pending.keys():
var cb: Dictionary = _pending[seq]
if cb[&"on_error"].is_valid():
cb[&"on_error"].call("DISCONNECTED", "Connection lost.")
cb[&"on_error"].call(error_code, error_msg)
_pending.clear()
_ping_seq = -1
_ping_sent_at = -1.0