Add simple disconnection count to metrics

This commit is contained in:
Tulir Asokan
2020-06-17 17:57:14 +03:00
parent 689202f43d
commit 5a04f6c871
2 changed files with 20 additions and 0 deletions

View File

@@ -561,6 +561,7 @@ func (user *User) HandleError(err error) {
user.log.Errorfln("WhatsApp error: %v", err)
}
if closed, ok := err.(*whatsapp.ErrConnectionClosed); ok {
user.bridge.Metrics.TrackDisconnection(user.MXID)
if closed.Code == 1000 && user.cleanDisconnection {
user.cleanDisconnection = false
user.log.Infoln("Clean disconnection by server")
@@ -568,6 +569,7 @@ func (user *User) HandleError(err error) {
}
go user.tryReconnect(fmt.Sprintf("Your WhatsApp connection was closed with websocket status code %d", closed.Code))
} else if failed, ok := err.(*whatsapp.ErrConnectionFailed); ok {
user.bridge.Metrics.TrackDisconnection(user.MXID)
user.ConnectionErrors++
go user.tryReconnect(fmt.Sprintf("Your WhatsApp connection failed: %v", failed.Err))
}