How to prevent Resty client from logging request timeout to the console? #690
-
HI guys, I've tried to use const (
timeout = 2500 * time.Millisecond // timeout on each request
retryCount = 3
initialRetryWaitTime = 650 * time.Millisecond
retryMaxWaitTime = 2 * time.Second
)
func NewClient() *resty.Client{
r := resty.New()
r.SetDebug(false)
r.SetDisableWarn(false)
r.DisableTrace()
r.SetTimeout(timeout)
r.SetRetryCount(retryCount) // enable retries
r.SetRetryWaitTime(initialRetryWaitTime) // Default is 100 milliseconds.
r.SetRetryMaxWaitTime(retryMaxWaitTime) // Default is 2 seconds.
r.AddRetryCondition(
func(r *resty.Response, err error) bool {
if r != nil {
return r.StatusCode() == http.StatusTooManyRequests ||
r.StatusCode() == http.StatusServiceUnavailable
}
return false // do not retry otherwise
},
)
return &r
} Console: 2023/08/30 18:22:04.756614 ERROR RESTY Post "http://localhost:8081/....": context deadline exceeded (Client.Timeout exceeded while awaiting headers), Attempt 1 |
Beta Was this translation helpful? Give feedback.
Answered by
jeevatkm
Sep 17, 2023
Replies: 1 comment
-
@BigBoulard You could control log message via setting your own logger |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jeevatkm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@BigBoulard You could control log message via setting your own logger
SetLogger