-
Notifications
You must be signed in to change notification settings - Fork 0
/
derp_codes.go
65 lines (52 loc) · 1.76 KB
/
derp_codes.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
54
55
56
57
58
59
60
61
62
63
64
65
package derp
// NotFound returns TRUE if the error `Code` is a 404 / Not Found error.
func NotFound(err error) bool {
if isNil(err) {
return false
}
if coder, ok := err.(ErrorCodeGetter); ok {
return coder.GetErrorCode() == CodeNotFoundError
}
return err.Error() == "not found"
}
// NilOrNotFound returns TRUE if the error is nil or a 404 / Not Found error.
// All other errors return FALSE
func NilOrNotFound(err error) bool {
if isNil(err) {
return true
}
if NotFound(err) {
return true
}
return false
}
// IsInformational returns TRUE if the error `Code` is a 1xx / Informational error.
// https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#1xx_informational_response
func IsInformational(err error) bool {
code := ErrorCode(err)
return code >= 100 && code < 200
}
// IsSuccess returns TRUE if the error `Code` is a 2xx / Success error.
// https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#2xx_success
func IsSuccess(err error) bool {
code := ErrorCode(err)
return code >= 200 && code < 300
}
// IsRedirection returns TRUE if the error `Code` is a 3xx / Redirection error.
// https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_redirection
func IsRedirection(err error) bool {
code := ErrorCode(err)
return code >= 300 && code < 400
}
// IsClientError returns TRUE if the error `Code` is a 4xx / Client Error error.
// https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_client_errors
func IsClientError(err error) bool {
code := ErrorCode(err)
return code >= 400 && code < 500
}
// IsServerError returns TRUE if the error `Code` is a 5xx / Server Error error.
// https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_server_errors
func IsServerError(err error) bool {
code := ErrorCode(err)
return code >= 500 && code < 600
}