@@ -651,12 +651,42 @@ impl ChatClient {
651651 Ok ( input:: ClientUserInput :: ListUsers ) => {
652652 let message = ChatMessage :: try_new( MessageTypes :: ListUsers , None )
653653 . map_err( |e| io:: Error :: other( format!( "Failed to create ListUsers message: {e:?}" ) ) ) ?;
654- self . send_message_chunked( message) . await
655- . map_err( |e| io:: Error :: other( format!( "Failed to send ListUsers message: {e:?}" ) ) ) ?;
654+ if let Err ( e) = self . send_message_chunked( message) . await {
655+ logger:: log_warning( "Connection lost while sending message" ) ;
656+
657+ if !self . was_kicked {
658+ match self . reconnect( ) . await {
659+ Ok ( ( ) ) => {
660+ // Connection restored
661+ }
662+ Err ( reconnect_err) => {
663+ logger:: log_error( & format!( "Failed to reconnect: {:?}" , reconnect_err) ) ;
664+ return Err ( io:: Error :: other( format!( "Failed to send ListUsers message: {e:?}" ) ) ) ;
665+ }
666+ }
667+ }
668+ }
656669 }
657670 Ok ( user_input) => {
658671 if let Err ( e) = self . handle_user_input( user_input) . await {
659- logger:: log_error( & format!( "Error: {e:?}" ) ) ;
672+ // Check if this is a connection error that needs reconnection
673+ if matches!( e, ChatClientError :: IoError ) {
674+ logger:: log_warning( "Connection lost while sending message" ) ;
675+
676+ if !self . was_kicked {
677+ match self . reconnect( ) . await {
678+ Ok ( ( ) ) => {
679+ // Connection restored
680+ }
681+ Err ( reconnect_err) => {
682+ logger:: log_error( & format!( "Failed to reconnect: {:?}" , reconnect_err) ) ;
683+ return Err ( io:: Error :: other( "Reconnection failed" ) ) ;
684+ }
685+ }
686+ }
687+ } else {
688+ logger:: log_error( & format!( "Error: {e:?}" ) ) ;
689+ }
660690 }
661691 }
662692 Err ( e) => {
0 commit comments