proxy: improve logging and reconnecting

This commit is contained in:
Jens Langhammer 2020-09-18 21:54:23 +02:00
parent 316e6cb17f
commit 6ab8794754
1 changed files with 5 additions and 3 deletions

View File

@ -55,7 +55,8 @@ func (ac *APIController) startWSHandler() {
var wsMsg websocketMessage var wsMsg websocketMessage
err := ac.wsConn.ReadJSON(&wsMsg) err := ac.wsConn.ReadJSON(&wsMsg)
if err != nil { if err != nil {
ac.logger.Println("read:", err) ac.logger.WithField("loop", "ws-handler").Println("read:", err)
ac.wsConn.CloseAndReconnect()
return return
} }
if wsMsg.Instruction != WebsocketInstructionAck { if wsMsg.Instruction != WebsocketInstructionAck {
@ -64,7 +65,7 @@ func (ac *APIController) startWSHandler() {
if wsMsg.Instruction == WebsocketInstructionTriggerUpdate { if wsMsg.Instruction == WebsocketInstructionTriggerUpdate {
err := ac.UpdateIfRequired() err := ac.UpdateIfRequired()
if err != nil { if err != nil {
ac.logger.WithError(err).Debug("Failed to update") ac.logger.WithField("loop", "ws-handler").WithError(err).Debug("Failed to update")
} }
} }
} }
@ -78,7 +79,8 @@ func (ac *APIController) startWSHealth() {
} }
err := ac.wsConn.WriteJSON(aliveMsg) err := ac.wsConn.WriteJSON(aliveMsg)
if err != nil { if err != nil {
ac.logger.Println("write:", err) ac.logger.WithField("loop", "ws-health").Println("write:", err)
ac.wsConn.CloseAndReconnect()
return return
} }
} }