-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.go
84 lines (72 loc) · 2.42 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package pkgo
import (
"fmt"
"emperror.dev/errors"
)
// Errors
const (
ErrNoToken = errors.Sentinel("pkgo: no token in session, can't hit endpoints requiring authentication")
ErrInvalidID = errors.Sentinel("pkgo: not a 5-character ID")
ErrInvalidSnowflake = errors.Sentinel("pkgo: not a valid Discord snowflake")
ErrMsgNotFound = errors.Sentinel("pkgo: message not found")
ErrPrivacyInvalid = errors.Sentinel("pkgo: invalid privacy setting")
ErrInvalidProxyTag = errors.Sentinel("pkgo: invalid proxy tag")
)
// PKAPIError is an error returned by the PluralKit API
type PKAPIError struct {
StatusCode int `json:"-"`
Code int `json:"code"`
RetryAfter *int `json:"retry_after,omitempty"`
Message string `json:"message"`
Errors map[string][]ModelError `json:"errors,omitempty"`
}
func (e PKAPIError) Error() string {
if e.RetryAfter != nil {
return fmt.Sprintf("rate limited, retry after %dms", *e.RetryAfter)
}
return fmt.Sprintf("%d: %s", e.Code, e.Message)
}
// Error codes
const (
SystemNotFound = 20001
MemberNotFound = 20002
MemberNotFoundWithRef = 20003
GroupNotFound = 20004
GroupNotFoundWithRef = 20005
MessageNotFound = 20006
SwitchNotFound = 20007
SwitchNotFoundPublic = 20008
SystemGuildNotFound = 20009
MemberGuildNotFound = 20010
UnauthorizedMemberList = 30001
UnauthorizedGroupList = 30002
UnauthorizedGroupMemberList = 30003
UnauthorizedCurrentFronters = 30004
UnauthorizedFrontHistory = 30005
NotOwnMember = 30006
NotOwnGroup = 30007
NotOwnMemberWithRef = 30008
NotOwnGroupWithRef = 30009
MissingAutoproxyMember = 40002
DuplicateMembersInList = 40003
SameSwitchMembers = 40004
SameSwitchTimestamp = 40005
InvalidSwitchID = 40006
MemberLimitReached = 40007
GroupLimitReached = 40008
Unimplemented = 50001
)
// ModelError ...
type ModelError struct {
Message string `json:"message"`
MaxLength int `json:"max_length"`
ActualLength int `json:"actual_length"`
}
// InvalidError is returned when the data for a PATCH or POST endpoint is invalid.
type InvalidError struct {
field string
value string
}
func (e *InvalidError) Error() string {
return fmt.Sprintf(`invalid value in field "%s": "%s"`, e.field, e.value)
}