-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathservererror.go
46 lines (39 loc) · 1006 Bytes
/
servererror.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 kanka
import (
"fmt"
"net/http"
)
// serverError represents an error originating from another server.
type serverError struct {
code int
status string
temporary bool
}
// Error returns the status message of an error.
func (e *serverError) Error() string {
return fmt.Sprintf("server responded with status '%s'", e.status)
}
// Temporary returns true if the error is temporary.
func (e *serverError) Temporary() bool {
return e.temporary
}
// isSuccess returns true if the provided status code is of the 200 type.
func isSuccess(code int) bool {
if code >= 200 && code < 300 {
return true
}
return false
}
// isTemporary returns true if the provided status code represents a temporary
// error according to Kanka.
// For more information, visit: https://kanka.io/en-US/docs/1.0/setup#endpoints
func isTemporary(code int) bool {
switch code {
case http.StatusMisdirectedRequest:
return true
case http.StatusTooManyRequests:
return true
default:
return false
}
}