From 2381eb029b0efbe5e35edddfb662bc137043691e Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 16 May 2019 18:18:11 +0300 Subject: [PATCH] Report WhatsApp server connection errors to user too. Fixes #18 --- commands.go | 5 ++++- user.go | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/commands.go b/commands.go index b006e99..74ce7a2 100644 --- a/commands.go +++ b/commands.go @@ -118,7 +118,10 @@ const cmdLoginHelp = `login - Authenticate this Bridge as WhatsApp Web Client` // CommandLogin handles login command func (handler *CommandHandler) CommandLogin(ce *CommandEvent) { if ce.User.Conn == nil { - ce.User.Connect(true) + if !ce.User.Connect(true) { + ce.User.log.Debugln("Connect() returned false, assuming error was logged elsewhere and canceling login.") + return + } } ce.User.Login(ce) } diff --git a/user.go b/user.go index 27bbcca..52d0ece 100644 --- a/user.go +++ b/user.go @@ -152,13 +152,17 @@ func (user *User) Connect(evenIfNoSession bool) bool { conn, err := whatsapp.NewConn(timeout * time.Second) if err != nil { user.log.Errorln("Failed to connect to WhatsApp:", err) + msg := format.RenderMarkdown(fmt.Sprintf("\u26a0 Failed to connect to WhatsApp server. " + + "This indicates a network problem on the bridge server. See bridge logs for more info.")) + _, _ = user.bridge.Bot.SendMessageEvent(user.ManagementRoom, mautrix.EventMessage, msg) return false } user.Conn = whatsappExt.ExtendConn(conn) _ = user.Conn.SetClientName("Mautrix-WhatsApp bridge", "mx-wa") user.log.Debugln("WhatsApp connection successful") user.Conn.AddHandler(user) - return user.RestoreSession() + user.RestoreSession() + return true } func (user *User) RestoreSession() bool {