File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,27 @@ const (
24
24
ErrForbidden
25
25
)
26
26
27
+ func (e ErrorType ) Error () string {
28
+ return e .String ()
29
+ }
30
+
31
+ func (e ErrorType ) String () string {
32
+ switch e {
33
+ case ErrNormal :
34
+ return "command failed"
35
+ case ErrClient :
36
+ return "invalid argument"
37
+ case ErrImplementation :
38
+ return "internal error"
39
+ case ErrRateLimited :
40
+ return "rate limited"
41
+ case ErrForbidden :
42
+ return "request forbidden"
43
+ default :
44
+ return "unknown error code"
45
+ }
46
+ }
47
+
27
48
// Error is a struct for marshalling errors
28
49
type Error struct {
29
50
Message string
@@ -42,6 +63,12 @@ func (e Error) Error() string {
42
63
return e .Message
43
64
}
44
65
66
+ // Unwrap returns the base error (an ErrorType). Works with go 1.13 error
67
+ // helpers.
68
+ func (e Error ) Unwrap () error {
69
+ return e .Code
70
+ }
71
+
45
72
func (e Error ) MarshalJSON () ([]byte , error ) {
46
73
return json .Marshal (struct {
47
74
Message string
You can’t perform that action at this time.
0 commit comments