Skip to content

Commit

Permalink
fix(telegram): handle auth errors on reconnect
Browse files Browse the repository at this point in the history
Fix #1458
  • Loading branch information
ernado committed Nov 28, 2024
1 parent db21b9f commit 32dcd2a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion telegram/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/gotd/td/exchange"
"github.com/gotd/td/tdsync"
"github.com/gotd/td/telegram/auth"
"github.com/gotd/td/tgerr"
)

func (c *Client) runUntilRestart(ctx context.Context) error {
Expand Down Expand Up @@ -54,7 +55,17 @@ func (c *Client) runUntilRestart(ctx context.Context) error {
}

func (c *Client) isPermanentError(err error) bool {
return errors.Is(err, exchange.ErrKeyFingerprintNotFound)
// See https://github.com/gotd/td/issues/1458.
if errors.Is(err, exchange.ErrKeyFingerprintNotFound) {
return true
}
if tgerr.Is(err, "AUTH_KEY_UNREGISTERED") || tgerr.Is(err, "SESSION_EXPIRED") {
return true
}
if auth.IsUnauthorized(err) {
return true
}
return false
}

func (c *Client) reconnectUntilClosed(ctx context.Context) error {
Expand Down

0 comments on commit 32dcd2a

Please sign in to comment.