From ae92d71d5ad8eb3b3a1b8d36a9a55caf0b6cdd74 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 16 May 2019 01:56:33 +0300 Subject: [PATCH] Handle connection failures like disconnections --- user.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/user.go b/user.go index d02fa13..e78da57 100644 --- a/user.go +++ b/user.go @@ -234,12 +234,19 @@ func (user *User) HandleError(err error) { closed, ok := err.(*whatsapp.ErrConnectionClosed) if ok { if closed.Code != 1000 { - msg := fmt.Sprintf("\u26a0 Your WhatsApp connection failed with websocket status code %d.\n\n"+ + msg := fmt.Sprintf("\u26a0 Your WhatsApp connection was closed with websocket status code %d.\n\n"+ "Use the `reconnect` command to reconnect.", closed.Code) _, _ = user.bridge.Bot.SendMessageEvent(user.ManagementRoom, mautrix.EventMessage, format.RenderMarkdown(msg)) } user.Connected = false } + failed, ok := err.(*whatsapp.ErrConnectionFailed) + if ok { + msg := fmt.Sprintf("\u26a0 Your WhatsApp connection failed: %v.\n\n"+ + "Use the `reconnect` command to reconnect.", failed.Err) + _, _ = user.bridge.Bot.SendMessageEvent(user.ManagementRoom, mautrix.EventMessage, format.RenderMarkdown(msg)) + user.Connected = false + } } func (user *User) HandleJSONParseError(err error) {