-
Notifications
You must be signed in to change notification settings - Fork 7
/
error.go
50 lines (43 loc) · 949 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
package client
import (
"net/http"
)
type httpError struct {
code int
reason string
}
func (e *httpError) Error() string {
return http.StatusText(e.code) + ": " + e.reason
}
// Is4xx returns true if err contains 4xx status code
func Is4xx(err error) bool {
err2, ok := err.(*httpError)
if !ok {
return false
}
return 400 <= err2.code && err2.code < 500
}
// IsNotFound returns true if err contains 404 status code
func IsNotFound(err error) bool {
err2, ok := err.(*httpError)
if !ok {
return false
}
return err2.code == http.StatusNotFound
}
// IsConflict returns true if err contains 409 status code
func IsConflict(err error) bool {
err2, ok := err.(*httpError)
if !ok {
return false
}
return err2.code == http.StatusConflict
}
// Is5xx returns true if err contains 5xx status code
func Is5xx(err error) bool {
err2, ok := err.(*httpError)
if !ok {
return false
}
return 500 <= err2.code && err2.code < 600
}