diff --git a/pkg/wsapi/api.go b/pkg/wsapi/api.go index 02be019..5ecd3f8 100644 --- a/pkg/wsapi/api.go +++ b/pkg/wsapi/api.go @@ -11,6 +11,7 @@ import ( "github.com/gorilla/websocket" "github.com/labstack/echo/v4" + "github.com/mitchellh/mapstructure" "github.com/rs/zerolog/log" ) @@ -106,14 +107,18 @@ func (ws *wsSession) Go() error { for { _, rdr, err := ws.NextReader() - if err != nil { + switch { + case websocket.IsCloseError(err, websocket.CloseGoingAway): + return nil + case err == nil: + case err != nil: log.Error().Err(err).Str("remote", ws.ec.Request().RemoteAddr).Msg("websocket read fail") return err } err = ws.h.handleMsg(rdr) if err != nil { - return err + log.Error().Err(err).Msg("handleMsg") } } } @@ -190,5 +195,15 @@ func (ws *cmdHandler) handleMsg(r io.Reader) error { } nd := newData(cmd) + err = mapstructure.Decode(&msgMap, &nd) + if err != nil { + ws.writeError(id, Error{ + Code: "invalid_format", + Message: err.Error(), + }) + + return nil + } + return hand(ws, id, cmd, nd) }