Skip to content

Commit

Permalink
Use BAD_CREDENTIALS for relevant WhatsApp error codes
Browse files Browse the repository at this point in the history
This is more accurate than `UNKNOWN_ERROR`, even if we do subsequently
reconnect by resetting the WA device.
  • Loading branch information
Fizzadar committed Jul 22, 2024
1 parent 76b2a2a commit 58c77b9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -1046,8 +1046,11 @@ func (user *User) e2eeEventHandler(rawEvt any) {
user.BridgeState.Send(user.waState)
go user.sendMarkdownBridgeAlert(context.TODO(), "Error in WhatsApp connection: %s", evt.PermanentDisconnectDescription())
case events.PermanentDisconnect:
stateEvent := status.StateUnknownError

switch e := evt.(type) {
case *events.LoggedOut:
stateEvent = status.StateBadCredentials
if e.Reason == events.ConnectFailureLoggedOut && !e.OnConnect && user.canReconnect() {
user.resetWADevice()
user.log.Debug().Msg("Doing full reconnect after WhatsApp 401 error")
Expand All @@ -1064,15 +1067,16 @@ func (user *User) e2eeEventHandler(rawEvt any) {
user.log.Debug().Msg("Reconnecting e2ee client after WhatsApp 415 error")
go user.connectE2EE()
} else if e.Reason == events.ConnectFailureReason(418) {
// TODO: what is error 418?
// WA 418 appears to indicate logout/bad credentials
stateEvent = status.StateBadCredentials
user.resetWADevice()
user.log.Debug().Msg("Doing full reconnect after WhatsApp 418 error")
go user.FullReconnect()
}
}

user.waState = status.BridgeState{
StateEvent: status.StateUnknownError,
StateEvent: stateEvent,
Error: WAPermanentError,
Message: evt.PermanentDisconnectDescription(),
}
Expand Down

0 comments on commit 58c77b9

Please sign in to comment.