forked from superfly/flyctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
46 lines (38 loc) · 844 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
package api
import "net/http"
type ApiError struct {
WrappedError error
Message string
Status int
}
func (e *ApiError) Error() string { return e.Message }
func ErrorFromResp(resp *http.Response) *ApiError {
return &ApiError{
Message: resp.Status,
Status: resp.StatusCode,
}
}
func IsNotAuthenticatedError(err error) bool {
if apiErr, ok := err.(*ApiError); ok {
return apiErr.Status == 401
}
return false
}
func IsNotFoundError(err error) bool {
if apiErr, ok := err.(*ApiError); ok {
return apiErr.Status == 404
}
return false
}
func IsServerError(err error) bool {
if apiErr, ok := err.(*ApiError); ok {
return apiErr.Status >= 500
}
return false
}
func IsClientError(err error) bool {
if apiErr, ok := err.(*ApiError); ok {
return apiErr.Status >= 400 && apiErr.Status < 500
}
return false
}