-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.go
36 lines (29 loc) · 970 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
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")
)
// StatusError is returned when a request returns a non-200 status code
type StatusError struct {
Code int
Status string
}
func (e *StatusError) Error() string {
return fmt.Sprintf("http status code %v: %v", e.Code, e.Status)
}
// 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)
}