From 3c274e6d35eb5152f251b72b4caa1313a6ffe604 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 17 Feb 2022 15:33:31 +0200 Subject: [PATCH] Add proper error message for outdated client errors --- commands.go | 2 ++ go.mod | 2 +- go.sum | 4 ++-- provisioning.go | 6 ++++++ user.go | 4 ++++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/commands.go b/commands.go index 935e0c5..4abf2b3 100644 --- a/commands.go +++ b/commands.go @@ -522,6 +522,8 @@ func (handler *CommandHandler) CommandLogin(ce *CommandEvent) { ce.Reply("QR code timed out. Please restart the login.") case whatsmeow.QRChannelErrUnexpectedEvent.Event: ce.Reply("Failed to log in: unexpected connection event from server") + case whatsmeow.QRChannelClientOutdated.Event: + ce.Reply("Failed to log in: outdated client. The bridge must be updated to continue.") case whatsmeow.QRChannelScannedWithoutMultidevice.Event: ce.Reply("Please enable the WhatsApp multidevice beta and scan the QR code again.") case "error": diff --git a/go.mod b/go.mod index 6856a31..fbc4919 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/prometheus/client_golang v1.11.1 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/tidwall/gjson v1.14.0 - go.mau.fi/whatsmeow v0.0.0-20220217121823-b7d4c5a8e8cc + go.mau.fi/whatsmeow v0.0.0-20220217133111-7d4c399d0640 golang.org/x/image v0.0.0-20211028202545-6944b10bf410 golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd google.golang.org/protobuf v1.27.1 diff --git a/go.sum b/go.sum index 3ec0410..e86e2aa 100644 --- a/go.sum +++ b/go.sum @@ -120,8 +120,8 @@ github.com/tidwall/sjson v1.2.4 h1:cuiLzLnaMeBhRmEv00Lpk3tkYrcxpmbU81tAY4Dw0tc= github.com/tidwall/sjson v1.2.4/go.mod h1:098SZ494YoMWPmMO6ct4dcFnqxwj9r/gF0Etp19pSNM= go.mau.fi/libsignal v0.0.0-20211109153248-a67163214910 h1:9FFhG0OmkuMau5UEaTgiUQ+7cSbtbOQ7hiWKdN8OI3I= go.mau.fi/libsignal v0.0.0-20211109153248-a67163214910/go.mod h1:AufGrvVh+00Nc07Jm4hTquh7yleZyn20tKJI2wCPAKg= -go.mau.fi/whatsmeow v0.0.0-20220217121823-b7d4c5a8e8cc h1:nmKmURePfVfpK+qLeAZvJIMbgpAKtfYcqeXwXAaFUls= -go.mau.fi/whatsmeow v0.0.0-20220217121823-b7d4c5a8e8cc/go.mod h1:NNI4Ah/B27mfQNChJMD1iSO8+HS+fQ4WqNuQ8Mh2/XI= +go.mau.fi/whatsmeow v0.0.0-20220217133111-7d4c399d0640 h1:8WEXxj18qt6B8KhCW510qtNZjQUiqV2u3nvhNy8HV30= +go.mau.fi/whatsmeow v0.0.0-20220217133111-7d4c399d0640/go.mod h1:NNI4Ah/B27mfQNChJMD1iSO8+HS+fQ4WqNuQ8Mh2/XI= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= diff --git a/provisioning.go b/provisioning.go index c52cf58..06709d7 100644 --- a/provisioning.go +++ b/provisioning.go @@ -455,6 +455,12 @@ func (prov *ProvisioningAPI) Login(w http.ResponseWriter, r *http.Request) { Error: "Got unexpected event while waiting for QRs, perhaps you're already logged in?", ErrCode: "unexpected event", }) + case whatsmeow.QRChannelClientOutdated.Event: + user.log.Debugln("Login via provisioning API failed due to outdated client") + _ = c.WriteJSON(Error{ + Error: "Got client outdated error while waiting for QRs. The bridge must be updated to continue.", + ErrCode: "bridge outdated", + }) case whatsmeow.QRChannelScannedWithoutMultidevice.Event: _ = c.WriteJSON(Error{ Error: "Please enable the WhatsApp multidevice beta and scan the QR code again.", diff --git a/user.go b/user.go index 7342ddf..bc57888 100644 --- a/user.go +++ b/user.go @@ -591,6 +591,10 @@ func (user *User) HandleEvent(event interface{}) { case *events.ConnectFailure: go user.sendBridgeState(BridgeState{StateEvent: StateUnknownError, Message: fmt.Sprintf("Unknown connection failure: %s", v.Reason)}) user.bridge.Metrics.TrackConnectionState(user.JID, false) + case *events.ClientOutdated: + user.log.Errorfln("Got a client outdated connect failure. The bridge is likely out of date, please update immediately.") + go user.sendBridgeState(BridgeState{StateEvent: StateUnknownError, Message: "Connect failure: 405 client outdated"}) + user.bridge.Metrics.TrackConnectionState(user.JID, false) case *events.TemporaryBan: go user.sendBridgeState(BridgeState{StateEvent: StateBadCredentials, Message: v.String()}) user.bridge.Metrics.TrackConnectionState(user.JID, false)