forked from cep21/circuit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
71 lines (56 loc) · 1.94 KB
/
errors.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
66
67
68
69
70
71
package circuit
import "fmt"
var errThrottledConcucrrentCommands = &circuitError{concurrencyLimitReached: true, msg: "throttling connections to command"}
var errCircuitOpen = &circuitError{circuitOpen: true, msg: "circuit is open"}
// circuitError is used for internally generated errors
type circuitError struct {
concurrencyLimitReached bool
circuitOpen bool
msg string
}
func (m *circuitError) Error() string {
return fmt.Sprintf("%s: concurrencyReached=%t circuitOpen=%t", m.msg, m.ConcurrencyLimitReached(), m.CircuitOpen())
}
func (m *circuitError) ConcurrencyLimitReached() bool {
return m.concurrencyLimitReached
}
// Deprecated: A typo. Will be removed in future releases. Use CircuitOpen instead
func (m *circuitError) CiruitOpen() bool {
return m.CircuitOpen()
}
func (m *circuitError) CircuitOpen() bool {
return m.circuitOpen
}
// BadRequest is implemented by an error returned by runFunc if you want to consider the requestor bad, not the circuit
// bad. See http://netflix.github.io/Hystrix/javadoc/com/netflix/hystrix/exception/HystrixBadRequestException.html
// and https://github.com/Netflix/Hystrix/wiki/How-To-Use#error-propagation for information.
type BadRequest interface {
BadRequest() bool
}
// IsBadRequest returns true if the error is of type BadRequest
func IsBadRequest(err error) bool {
if err == nil {
return false
}
br, ok := err.(BadRequest)
return ok && br.BadRequest()
}
// SimpleBadRequest is a simple wrapper for an error to mark it as a bad request
type SimpleBadRequest struct {
Err error
}
// Cause returns the wrapped error
func (s SimpleBadRequest) Cause() error {
return s.Err
}
// Cause returns the wrapped error
func (s SimpleBadRequest) Error() string {
return s.Err.Error()
}
// BadRequest always returns true
func (s SimpleBadRequest) BadRequest() bool {
return true
}
var _ error = &SimpleBadRequest{}
var _ BadRequest = &SimpleBadRequest{}
var _ error = &circuitError{}