-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrs.go
More file actions
29 lines (25 loc) · 1.02 KB
/
Copy patherrs.go
File metadata and controls
29 lines (25 loc) · 1.02 KB
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
package goratelimit
import (
"fmt"
"strings"
)
const docBase = "https://pkg.go.dev/github.com/krishna-kudari/ratelimit"
// validationErr returns an error with an actionable message and a doc link.
func validationErr(msg, suggestion string) error {
return fmt.Errorf("goratelimit: %s. %s See %s", msg, suggestion, docBase)
}
// redisErr wraps a Redis backend error with a suggestion and optional Cluster hint.
func redisErr(err error, opts *Options) error {
if err == nil {
return nil
}
suggestion := "Check connection string and that Redis is reachable."
if strings.Contains(strings.ToLower(err.Error()), "connection refused") {
suggestion = "Is Redis running? Try: docker run -d -p 6379:6379 redis:alpine. See " + docBase + "#New"
}
if opts != nil && !opts.HashTag &&
(strings.Contains(err.Error(), "CROSSSLOT") || strings.Contains(err.Error(), "MOVED")) {
suggestion += " Using Redis Cluster? Enable WithHashTag(). See " + docBase + "#WithHashTag"
}
return fmt.Errorf("goratelimit: redis error: %w. %s", err, suggestion)
}