-
-
Notifications
You must be signed in to change notification settings - Fork 135
/
auth.go
38 lines (32 loc) · 907 Bytes
/
auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package telegram
import (
"golang.org/x/xerrors"
"github.com/gotd/td/tg"
)
// SignUpRequired means that log in failed because corresponding account
// does not exist, so sign up is required.
type SignUpRequired struct {
TermsOfService tg.HelpTermsOfService
}
// Is returns true if err is SignUpRequired.
func (s *SignUpRequired) Is(err error) bool {
_, ok := err.(*SignUpRequired)
return ok
}
func (s *SignUpRequired) Error() string {
return "account with provided number does not exist (sign up required)"
}
// checkAuthResult checks that a is *tg.AuthAuthorization.
func (c *Client) checkAuthResult(a tg.AuthAuthorizationClass) error {
switch v := a.(type) {
case *tg.AuthAuthorization:
// Ok.
return nil
case *tg.AuthAuthorizationSignUpRequired:
return &SignUpRequired{
TermsOfService: v.TermsOfService,
}
default:
return xerrors.Errorf("got unexpected response %T", a)
}
}