-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
57 lines (48 loc) · 1.67 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
package goll
import (
"fmt"
"time"
)
var (
// ErrLoadRequestTimeout is a sentinel for the error that
// occurs when autoretrying a submission (ex. with SubmitUntil)
// failed because the maximum timeout was reached
ErrLoadRequestTimeout = &LoadRequestTimeout{}
// ErrLoadRequestRejected is a sentinel for the error that
// occurs when a submission can't be accepted
// usually happens when:
// - the request asks for a load greater than the limiter maximum load
// - the request gets rejected and the limiter was built with SkipRetryInComputing = true
ErrLoadRequestRejected = &LoadRequestRejected{}
)
// LoadRequestTimeout is returned when autoretrying a submission (ex. with SubmitUntil)
// failed because the maximum timeout was reached
type LoadRequestTimeout struct {
AttemptsNumber uint64
WaitedFor time.Duration
}
func (e *LoadRequestTimeout) Error() string {
return fmt.Sprintf(
"LoadRequestTimeout: load submission failed and timed out after %v attempts in %v ms",
e.AttemptsNumber,
e.WaitedFor.Milliseconds(),
)
}
func (e *LoadRequestTimeout) Is(tgt error) bool {
_, ok := tgt.(*LoadRequestTimeout)
return ok
}
// LoadRequestRejected is returned when a submission can't be accepted
// usually happens when:
// - the request asks for a load greater than the limiter maximum load
// - the request gets rejected and the limiter was built with SkipRetryInComputing = true
type LoadRequestRejected struct {
Reason string
}
func (e *LoadRequestRejected) Error() string {
return fmt.Sprintf("LoadRequestRejected: the requested load can't be accepted (%v)", e.Reason)
}
func (e *LoadRequestRejected) Is(tgt error) bool {
_, ok := tgt.(*LoadRequestRejected)
return ok
}