-
-
Notifications
You must be signed in to change notification settings - Fork 131
/
auth.go
37 lines (31 loc) · 972 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
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 and returns authorization result or error.
func checkAuthResult(a tg.AuthAuthorizationClass) (*tg.AuthAuthorization, error) {
switch a := a.(type) {
case *tg.AuthAuthorization:
return a, nil // ok
case *tg.AuthAuthorizationSignUpRequired:
return nil, &SignUpRequired{
TermsOfService: a.TermsOfService,
}
default:
return nil, xerrors.Errorf("got unexpected response %T", a)
}
}