Skip to content

Commit

Permalink
set retry for any non 2xx response
Browse files Browse the repository at this point in the history
  • Loading branch information
fraidev committed Dec 20, 2023
1 parent 4e45d8c commit cbfcbe7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions middlewares/retry.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package middlewares

import (
"strconv"
"strings"

"github.com/labstack/echo/v4"
Expand All @@ -15,15 +16,13 @@ func Retry(config *utils.Config) echo.MiddlewareFunc {
}
err = next(c)

status := c.Response().Status
if status == 404 || status == 410 &&
strings.Contains(c.Request().URL.Path, "blocks") {
status := strconv.Itoa(c.Response().Status)
if !strings.HasPrefix(status, "2") {
c.Set("retry", true)
return next(c)
} else {
c.Set("retry", false)
}

c.Set("retry", false)
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func NewConfig() *Config {
store = &memoryStore
}

balancer := balancers.NewSameNodeBalancer(targets, retryTarget, configFile.LoadBalancer.TTL, store)
balancer := balancers.NewIPHashBalancer(targets, retryTarget, configFile.LoadBalancer.TTL, store)

transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
Expand Down

0 comments on commit cbfcbe7

Please sign in to comment.