-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
32 lines (26 loc) · 747 Bytes
/
errors.go
File metadata and controls
32 lines (26 loc) · 747 Bytes
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
package gomian
import (
"errors"
"fmt"
)
var (
// ErrCircuitOpen is returned when a request is rejected because the circuit is open.
ErrCircuitOpen = errors.New("circuit breaker is open")
)
// CircuitError represents an error that occurred within the circuit breaker.
type CircuitError struct {
Name string
Err error
}
// Error returns a string representation of the CircuitError.
func (e *CircuitError) Error() string {
return fmt.Sprintf("circuit breaker '%s': %v", e.Name, e.Err)
}
// Unwrap returns the underlying error.
func (e *CircuitError) Unwrap() error {
return e.Err
}
// IsCircuitOpen checks if the error is or wraps an ErrCircuitOpen error.
func IsCircuitOpen(err error) bool {
return errors.Is(err, ErrCircuitOpen)
}