mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
Fix noisy errors (#49)
* send message error. * read message error. * close webrtc conn only if not closed yet. * file upload no files received.
This commit is contained in:
parent
3e8d686c0f
commit
dfc7eb3882
@ -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-*")
|
||||
|
@ -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")
|
||||
}
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user