Skip to content

Commit

Permalink
add retry again
Browse files Browse the repository at this point in the history
  • Loading branch information
fraidev committed Dec 21, 2023
1 parent 1fbf30f commit 6661a01
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func main() {
e.Use(middlewares.DenyRoutes(config))
e.Use(middlewares.Cache(config))
e.Use(middlewares.Gzip(config))
e.Use(middlewares.Retry(config))
e.Use(middleware.ProxyWithConfig(*config.ProxyConfig))

// Start metrics server
Expand Down
32 changes: 32 additions & 0 deletions middlewares/retry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package middlewares

import (
"net/http"

"github.com/labstack/echo/v4"
"github.com/marigold-dev/tzproxy/utils"
)

func Retry(config *utils.Config) echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) (err error) {
if config.ConfigFile.TezosHostRetry == "" {
return next(c)
}

config.Logger.Debug().Msg("retry middleware")
err = next(c)

status := c.Response().Status
if status == http.StatusNotFound || status == http.StatusForbidden {
config.Logger.Debug().Msg("retry middleware: retrying")
c.Set("retry", status)
return next(c)
}

c.Set("retry", nil)

return err
}
}
}

0 comments on commit 6661a01

Please sign in to comment.