From 29217bf0cc6f7727bd1f5929d7305b55bc735a6d Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 16 Nov 2019 16:07:42 -0800 Subject: [PATCH] Show better errors in the logs --- websocket.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/websocket.go b/websocket.go index dde0f3c..b3a2c10 100644 --- a/websocket.go +++ b/websocket.go @@ -275,7 +275,7 @@ func (wsh *WebsocketHandler) SendErrorJson(err error) error { wsh.Mutex.Lock() defer wsh.Mutex.Unlock() - message := "an unexpected error was encountered during the websocket lifecycle" + message := "an unexpected error was encountered while handling this request" if wsh.JWT != nil && wsh.JWT.HasPermission(PermissionReceiveErrors) { message = err.Error() } @@ -285,7 +285,12 @@ func (wsh *WebsocketHandler) SendErrorJson(err error) error { wsm := WebsocketMessage{Event: ErrorEvent} wsm.Args = []string{m} - zap.S().Warnw("an error was encountered in the websocket process", zap.String("error_identifier", u.String()), zap.Error(err)) + zap.S().Errorw( + "an error was encountered in the websocket process", + zap.String("server", wsh.Server.Uuid), + zap.String("error_identifier", u.String()), + zap.Error(err), + ) return wsh.Connection.WriteJSON(wsm) } @@ -332,24 +337,18 @@ func (wsh *WebsocketHandler) HandleInbound(m WebsocketMessage) error { return nil } - var err error switch strings.Join(m.Args, "") { case "start": - err = wsh.Server.Environment.Start() - break + return wsh.Server.Environment.Start() case "stop": - err = wsh.Server.Environment.Stop() - break + return wsh.Server.Environment.Stop() case "restart": - break + return nil case "kill": - err = wsh.Server.Environment.Terminate(os.Kill) - break + return wsh.Server.Environment.Terminate(os.Kill) } - if err != nil { - return err - } + return nil } case SendServerLogsEvent: {