errors.go raw
1 package api
2
3 import "errors"
4
5 func IsBadResponse(err error, f func(b *BadResponse) bool) bool {
6 bad := &BadResponse{}
7 if !errors.As(err, &bad) {
8 return false
9 }
10 if f == nil {
11 return true
12 }
13 return f(bad)
14 }
15
16 func IsStatusCode(err error, code int) bool {
17 return IsBadResponse(err, func(bad *BadResponse) bool {
18 return bad.IsStatusCode(code)
19 })
20 }
21
22 func IsErrType(err error, name string) bool {
23 return IsBadResponse(err, func(bad *BadResponse) bool {
24 return bad.IsErrType(name)
25 })
26 }
27
28 func IsErrMsg(err error, msg string) bool {
29 return IsBadResponse(err, func(bad *BadResponse) bool {
30 return bad.IsErrMsg(msg)
31 })
32 }
33
34 func IsErrorCode(err error, code string) (bool, string) {
35 var (
36 res bool
37 attribute string
38 )
39 IsBadResponse(err, func(bad *BadResponse) bool {
40 res, attribute = bad.IsErrorCode(code)
41 return res
42 })
43 return res, attribute
44 }
45
46 func IsErrorCodeAttribute(err error, code string, attribute string) bool {
47 return IsBadResponse(err, func(bad *BadResponse) bool {
48 return bad.IsErrorCodeAttribute(code, attribute)
49 })
50 }
51
52 func IsAuthError(err error) bool {
53 return IsBadResponse(err, func(bad *BadResponse) bool {
54 return bad.IsAuthError()
55 })
56 }
57
58 func IsRequestFormatError(err error) bool {
59 return IsBadResponse(err, func(bad *BadResponse) bool {
60 return bad.IsRequestFormatError()
61 })
62 }
63
64 func IsParameterError(err error) bool {
65 return IsBadResponse(err, func(bad *BadResponse) bool {
66 return bad.IsParameterError()
67 })
68 }
69
70 func IsNotFound(err error) bool {
71 return IsBadResponse(err, func(bad *BadResponse) bool {
72 return bad.IsNotFound()
73 })
74 }
75
76 func IsTooManyRequests(err error) bool {
77 return IsBadResponse(err, func(bad *BadResponse) bool {
78 return bad.IsTooManyRequests()
79 })
80 }
81
82 func IsSystemError(err error) bool {
83 return IsBadResponse(err, func(bad *BadResponse) bool {
84 return bad.IsSystemError()
85 })
86 }
87
88 func IsGatewayTimeout(err error) bool {
89 return IsBadResponse(err, func(bad *BadResponse) bool {
90 return bad.IsGatewayTimeout()
91 })
92 }
93
94 func IsInvalidSchema(err error) bool {
95 return IsBadResponse(err, func(bad *BadResponse) bool {
96 return bad.IsInvalidSchema()
97 })
98 }
99