Skip to content

Commit

Permalink
fix validation of retry
Browse files Browse the repository at this point in the history
  • Loading branch information
fraidev committed Dec 20, 2023
1 parent 763bd3e commit 36bcb37
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions middlewares/retry.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package middlewares

import (
"strings"

"github.com/labstack/echo/v4"
"github.com/marigold-dev/tzproxy/utils"
)
Expand All @@ -14,9 +16,11 @@ func Retry(config *utils.Config) echo.MiddlewareFunc {
err = next(c)

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

return err
Expand Down
2 changes: 1 addition & 1 deletion utils/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (b *sameNodeBalancer) Next(c echo.Context) *middleware.ProxyTarget {
b.mutex.Lock()
defer b.mutex.Unlock()

if b.retryTarget != nil && c.Get("retry") != nil {
if b.retryTarget != nil && c.Get("retry") != nil && c.Get("retry").(bool) {
return b.retryTarget
}

Expand Down

0 comments on commit 36bcb37

Please sign in to comment.