From 847b9a3a90029b09f38595debbe17d2b0c0cda22 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 12 Mar 2024 17:51:45 +0200 Subject: [PATCH] Add better messages for expected google login errors --- commands.go | 21 ++++++++++++++++++++- provisioning.go | 8 ++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/commands.go b/commands.go index 338810e..c1fe1aa 100644 --- a/commands.go +++ b/commands.go @@ -19,6 +19,7 @@ package main import ( "context" "encoding/json" + "errors" "fmt" "strings" @@ -29,6 +30,7 @@ import ( "maunium.net/go/mautrix/event" "maunium.net/go/mautrix/id" + "go.mau.fi/mautrix-gmessages/libgm" "go.mau.fi/mautrix-gmessages/libgm/gmproto" ) @@ -156,6 +158,13 @@ func fnLoginGoogle(ce *WrappedCommandEvent) { ce.Reply("Send your Google cookies here, formatted as a key-value JSON object (see for details)") } +const ( + pairingErrMsgNoDevices = "No devices found. Make sure you've enabled account pairing in the Google Messages app on your phone." + pairingErrMsgIncorrectEmoji = "Incorrect emoji chosen on phone, please try again" + pairingErrMsgCancelled = "Pairing cancelled on phone" + pairingErrMsgTimeout = "Pairing timed out, please try again" +) + func fnLoginGoogleCookies(ce *WrappedCommandEvent) { ce.User.CommandState = nil if ce.User.Session != nil { @@ -183,7 +192,17 @@ func fnLoginGoogleCookies(ce *WrappedCommandEvent) { ce.Reply(emoji) }) if err != nil { - ce.Reply("Login failed: %v", err) + if errors.Is(err, libgm.ErrNoDevicesFound) { + ce.Reply(pairingErrMsgNoDevices) + } else if errors.Is(err, libgm.ErrIncorrectEmoji) { + ce.Reply(pairingErrMsgIncorrectEmoji) + } else if errors.Is(err, libgm.ErrPairingCancelled) { + ce.Reply(pairingErrMsgCancelled) + } else if errors.Is(err, libgm.ErrPairingTimeout) { + ce.Reply(pairingErrMsgTimeout) + } else { + ce.Reply("Login failed: %v", err) + } } else { ce.Reply("Login successful") } diff --git a/provisioning.go b/provisioning.go index 34c8a60..ad3595e 100644 --- a/provisioning.go +++ b/provisioning.go @@ -353,7 +353,7 @@ func (prov *ProvisioningAPI) GoogleLoginStart(w http.ResponseWriter, r *http.Req switch { case errors.Is(err, libgm.ErrNoDevicesFound): jsonResponse(w, http.StatusBadRequest, Error{ - Error: err.Error(), + Error: pairingErrMsgNoDevices, ErrCode: "no-devices-found", }) default: @@ -384,17 +384,17 @@ func (prov *ProvisioningAPI) GoogleLoginWait(w http.ResponseWriter, r *http.Requ }) case errors.Is(err, libgm.ErrIncorrectEmoji): jsonResponse(w, http.StatusBadRequest, Error{ - Error: err.Error(), + Error: pairingErrMsgIncorrectEmoji, ErrCode: "incorrect-emoji", }) case errors.Is(err, libgm.ErrPairingCancelled): jsonResponse(w, http.StatusBadRequest, Error{ - Error: err.Error(), + Error: pairingErrMsgCancelled, ErrCode: "pairing-cancelled", }) case errors.Is(err, libgm.ErrPairingTimeout): jsonResponse(w, http.StatusBadRequest, Error{ - Error: err.Error(), + Error: pairingErrMsgTimeout, ErrCode: "timeout", }) case errors.Is(err, context.Canceled):