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
|
//nolint
|
||||||
defer r.MultipartForm.RemoveAll()
|
defer r.MultipartForm.RemoveAll()
|
||||||
|
|
||||||
if !h.desktop.IsFileChooserDialogOpened() {
|
|
||||||
return utils.HttpUnprocessableEntity("file chooser dialog is not open")
|
|
||||||
}
|
|
||||||
|
|
||||||
req_files := r.MultipartForm.File["files"]
|
req_files := r.MultipartForm.File["files"]
|
||||||
if len(req_files) == 0 {
|
if len(req_files) == 0 {
|
||||||
return utils.HttpInternalServerError().
|
return utils.HttpBadRequest("no files received")
|
||||||
WithInternalErr(err).
|
}
|
||||||
WithInternalMsg("unable to copy uploaded file to destination file")
|
|
||||||
|
if !h.desktop.IsFileChooserDialogOpened() {
|
||||||
|
return utils.HttpUnprocessableEntity("file chooser dialog is not open")
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, err := os.MkdirTemp("", "neko-dialog-*")
|
dir, err := os.MkdirTemp("", "neko-dialog-*")
|
||||||
|
@ -109,7 +109,13 @@ func (peer *WebRTCPeerCtx) Destroy() {
|
|||||||
peer.mu.Lock()
|
peer.mu.Lock()
|
||||||
defer peer.mu.Unlock()
|
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")
|
peer.logger.Err(err).Msg("peer connection destroyed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package websocket
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -253,19 +254,26 @@ func (manager *WebSocketManagerCtx) connect(connection *websocket.Conn, r *http.
|
|||||||
Str("agent", r.UserAgent()).
|
Str("agent", r.UserAgent()).
|
||||||
Msg("connection ended")
|
Msg("connection ended")
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
logger.Debug().Msg("websocket close")
|
||||||
|
session.DisconnectWebSocketPeer(peer, false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
delayedDisconnect := false
|
delayedDisconnect := false
|
||||||
|
|
||||||
e, ok := err.(*websocket.CloseError)
|
e, ok := err.(*websocket.CloseError)
|
||||||
if !ok {
|
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
|
// client is expected to reconnect soon
|
||||||
delayedDisconnect = true
|
delayedDisconnect = true
|
||||||
} else {
|
} else {
|
||||||
switch e.Code {
|
switch e.Code {
|
||||||
case websocket.CloseNormalClosure:
|
case websocket.CloseNormalClosure:
|
||||||
logger.Info().Str("reason", e.Text).Msg("websocket close")
|
logger.Debug().Str("reason", e.Text).Msg("websocket close")
|
||||||
case websocket.CloseGoingAway:
|
case websocket.CloseGoingAway:
|
||||||
logger.Info().Str("reason", "going away").Msg("websocket close")
|
logger.Debug().Str("reason", "going away").Msg("websocket close")
|
||||||
default:
|
default:
|
||||||
logger.Warn().Err(err).Msg("websocket close")
|
logger.Warn().Err(err).Msg("websocket close")
|
||||||
// abnormal websocket closure:
|
// abnormal websocket closure:
|
||||||
|
@ -2,6 +2,7 @@ package websocket
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
@ -42,7 +43,8 @@ func (peer *WebSocketPeerCtx) Send(event string, payload any) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user