Don't disconnect when trying to reconnect and receiving a ErrAlreadyLoggedIn as a result.
This commit is contained in:
Remi Reuvekamp 2020-03-11 16:09:31 +01:00
parent 61268f8cc4
commit a932911c56
2 changed files with 11 additions and 9 deletions

View file

@ -247,12 +247,13 @@ func (handler *CommandHandler) CommandReconnect(ce *CommandEvent) {
} else if err == whatsapp.ErrLoginInProgress { } else if err == whatsapp.ErrLoginInProgress {
ce.Reply("A login or reconnection is already in progress.") ce.Reply("A login or reconnection is already in progress.")
return return
} else if err == whatsapp.ErrAlreadyLoggedIn {
ce.Reply("You were already connected.")
return
} }
if err != nil { if err != nil {
ce.User.log.Warnln("Error while reconnecting:", err) ce.User.log.Warnln("Error while reconnecting:", err)
if err == whatsapp.ErrAlreadyLoggedIn { if err.Error() == "restore session connection timed out" {
ce.Reply("You were already connected.")
} else if err.Error() == "restore session connection timed out" {
ce.Reply("Reconnection timed out. Is WhatsApp on your phone reachable?") ce.Reply("Reconnection timed out. Is WhatsApp on your phone reachable?")
} else { } else {
ce.Reply("Unknown error while reconnecting: %v", err) ce.Reply("Unknown error while reconnecting: %v", err)

View file

@ -178,15 +178,16 @@ func (prov *ProvisioningAPI) Reconnect(w http.ResponseWriter, r *http.Request) {
ErrCode: "login in progress", ErrCode: "login in progress",
}) })
return return
} else if err == whatsapp.ErrAlreadyLoggedIn {
jsonResponse(w, http.StatusConflict, Error{
Error: "You were already connected.",
ErrCode: err.Error(),
})
return
} }
if err != nil { if err != nil {
user.log.Warnln("Error while reconnecting:", err) user.log.Warnln("Error while reconnecting:", err)
if err == whatsapp.ErrAlreadyLoggedIn { if err.Error() == "restore session connection timed out" {
jsonResponse(w, http.StatusConflict, Error{
Error: "You were already connected.",
ErrCode: err.Error(),
})
} else if err.Error() == "restore session connection timed out" {
jsonResponse(w, http.StatusForbidden, Error{ jsonResponse(w, http.StatusForbidden, Error{
Error: "Reconnection timed out. Is WhatsApp on your phone reachable?", Error: "Reconnection timed out. Is WhatsApp on your phone reachable?",
ErrCode: err.Error(), ErrCode: err.Error(),