Correctly report errors to admin users over the websocket; closes pterodactyl/panel#2709

This commit is contained in:
Dane Everitt 2020-12-06 15:10:08 -08:00
parent 70ea61f22f
commit bcf0c72e47
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -32,10 +32,9 @@ const (
) )
type Handler struct { type Handler struct {
sync.RWMutex sync.RWMutex `json:"-"`
Connection *websocket.Conn `json:"-"`
Connection *websocket.Conn jwt *tokens.WebsocketPayload
jwt *tokens.WebsocketPayload `json:"-"`
server *server.Server server *server.Server
uuid uuid.UUID uuid uuid.UUID
} }
@ -130,7 +129,6 @@ func (h *Handler) SendJson(v *Message) error {
Event: JwtErrorEvent, Event: JwtErrorEvent,
Args: []string{err.Error()}, Args: []string{err.Error()},
}) })
return nil return nil
} }
@ -219,8 +217,11 @@ func (h *Handler) SendErrorJson(msg Message, err error, shouldLog ...bool) error
Event: ErrorEvent, Event: ErrorEvent,
Args: []string{"an unexpected error was encountered while handling this request"}, Args: []string{"an unexpected error was encountered while handling this request"},
} }
if isJWTError || (j != nil && j.HasPermission(PermissionReceiveErrors)) { if isJWTError || (j != nil && j.HasPermission(PermissionReceiveErrors)) {
wsm.Event = JwtErrorEvent if isJWTError {
wsm.Event = JwtErrorEvent
}
wsm.Args = []string{err.Error()} wsm.Args = []string{err.Error()}
} }
@ -229,7 +230,7 @@ func (h *Handler) SendErrorJson(msg Message, err error, shouldLog ...bool) error
if !isJWTError && (len(shouldLog) == 0 || (len(shouldLog) == 1 && shouldLog[0] == true)) { if !isJWTError && (len(shouldLog) == 0 || (len(shouldLog) == 1 && shouldLog[0] == true)) {
h.server.Log().WithFields(log.Fields{"event": msg.Event, "error_identifier": u.String(), "error": err}). h.server.Log().WithFields(log.Fields{"event": msg.Event, "error_identifier": u.String(), "error": err}).
Error("failed to handle websocket process; an error was encountered processing an event") Errorf("error processing websocket event \"%s\"", msg.Event)
} }
return h.unsafeSendJson(wsm) return h.unsafeSendJson(wsm)
@ -267,7 +268,6 @@ func (h *Handler) HandleInbound(m Message) error {
Event: JwtErrorEvent, Event: JwtErrorEvent,
Args: []string{err.Error()}, Args: []string{err.Error()},
}) })
return nil return nil
} }
} }