-
Notifications
You must be signed in to change notification settings - Fork 2
/
error.go
53 lines (39 loc) · 880 Bytes
/
error.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
package foxerr
type Error interface {
// Satisfy the generic error interface.
error
// return the error defined by fox.ONE
Code() int
// return the error detail msg
Message() string
}
func New(code int, message ...string) Error {
return newBaseError(code, message...)
}
type RequestFailure interface {
Error
// The status code of the HTTP response.
StatusCode() int
}
func NewRequestFailure(err Error, statusCode int) RequestFailure {
return newRequestError(err, statusCode)
}
const NotFoxError = 0
func Code(err error) int {
if e, ok := err.(Error); ok {
return e.Code()
}
return NotFoxError
}
func MatchCode(err error, code int) bool {
return Code(err) == code
}
func IsFoxError(err error) bool {
return MatchCode(err, NotFoxError)
}
func StatusCode(err error) int {
if e, ok := err.(RequestFailure); ok {
return e.StatusCode()
}
return 0
}