diff --git a/internal/api/room/upload.go b/internal/api/room/upload.go index bba7b989..046c6d94 100644 --- a/internal/api/room/upload.go +++ b/internal/api/room/upload.go @@ -95,15 +95,13 @@ func (h *RoomHandler) uploadDialogPost(w http.ResponseWriter, r *http.Request) e //nolint defer r.MultipartForm.RemoveAll() - if !h.desktop.IsFileChooserDialogOpened() { - return utils.HttpUnprocessableEntity("file chooser dialog is not open") - } - req_files := r.MultipartForm.File["files"] if len(req_files) == 0 { - return utils.HttpInternalServerError(). - WithInternalErr(err). - WithInternalMsg("unable to copy uploaded file to destination file") + return utils.HttpBadRequest("no files received") + } + + if !h.desktop.IsFileChooserDialogOpened() { + return utils.HttpUnprocessableEntity("file chooser dialog is not open") } dir, err := os.MkdirTemp("", "neko-dialog-*") diff --git a/internal/webrtc/peer.go b/internal/webrtc/peer.go index 590b598e..5d0ae2a9 100644 --- a/internal/webrtc/peer.go +++ b/internal/webrtc/peer.go @@ -109,7 +109,13 @@ func (peer *WebRTCPeerCtx) Destroy() { peer.mu.Lock() defer peer.mu.Unlock() - err := peer.connection.Close() + var err error + + // if peer connection is not closed, close it + if peer.connection.ConnectionState() != webrtc.PeerConnectionStateClosed { + err = peer.connection.Close() + } + peer.logger.Err(err).Msg("peer connection destroyed") } diff --git a/internal/websocket/manager.go b/internal/websocket/manager.go index 5ad9a0f8..03da86b2 100644 --- a/internal/websocket/manager.go +++ b/internal/websocket/manager.go @@ -2,6 +2,7 @@ package websocket import ( "encoding/json" + "errors" "net/http" "sync" "time" @@ -253,19 +254,26 @@ func (manager *WebSocketManagerCtx) connect(connection *websocket.Conn, r *http. Str("agent", r.UserAgent()). Msg("connection ended") + if err == nil { + logger.Debug().Msg("websocket close") + session.DisconnectWebSocketPeer(peer, false) + return + } + delayedDisconnect := false e, ok := err.(*websocket.CloseError) if !ok { - logger.Err(err).Msg("read message error") + err = errors.Unwrap(err) // unwrap if possible + logger.Warn().Err(err).Msg("read message error") // client is expected to reconnect soon delayedDisconnect = true } else { switch e.Code { case websocket.CloseNormalClosure: - logger.Info().Str("reason", e.Text).Msg("websocket close") + logger.Debug().Str("reason", e.Text).Msg("websocket close") case websocket.CloseGoingAway: - logger.Info().Str("reason", "going away").Msg("websocket close") + logger.Debug().Str("reason", "going away").Msg("websocket close") default: logger.Warn().Err(err).Msg("websocket close") // abnormal websocket closure: diff --git a/internal/websocket/peer.go b/internal/websocket/peer.go index 203caa83..8722acb6 100644 --- a/internal/websocket/peer.go +++ b/internal/websocket/peer.go @@ -2,6 +2,7 @@ package websocket import ( "encoding/json" + "errors" "sync" "github.com/gorilla/websocket" @@ -42,7 +43,8 @@ func (peer *WebSocketPeerCtx) Send(event string, payload any) { }) if err != nil { - peer.logger.Err(err).Str("event", event).Msg("send message error") + err = errors.Unwrap(err) // unwrap if possible + peer.logger.Warn().Err(err).Str("event", event).Msg("send message error") return }