-
Notifications
You must be signed in to change notification settings - Fork 68
/
errors.go
43 lines (35 loc) · 918 Bytes
/
errors.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
39
40
41
42
43
package bot
import (
"errors"
"fmt"
)
var (
ErrorForbidden = errors.New("forbidden")
ErrorBadRequest = errors.New("bad request")
ErrorUnauthorized = errors.New("unauthorized")
ErrorTooManyRequests = errors.New("too many requests")
ErrorNotFound = errors.New("not found")
ErrorConflict = errors.New("conflict")
)
type TooManyRequestsError struct {
Message string
RetryAfter int
}
func (e *TooManyRequestsError) Error() string {
return fmt.Sprintf("%s: retry_after %d", e.Message, e.RetryAfter)
}
func IsTooManyRequestsError(err error) bool {
_, ok := err.(*TooManyRequestsError)
return ok
}
type MigrateError struct {
Message string
MigrateToChatID int
}
func (e *MigrateError) Error() string {
return fmt.Sprintf("%s: migrate_to_chat_id %d", e.Message, e.MigrateToChatID)
}
func IsMigrateError(err error) bool {
_, ok := err.(*MigrateError)
return ok
}