Skip to content

Commit

Permalink
additional info in status of retry
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrilevos committed Mar 28, 2024
1 parent d747812 commit e3d7d98
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions middlewares/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func Retry(config *config.Config) echo.MiddlewareFunc {
// Replace the request body with a buffer
c.Request().Body = io.NopCloser(bytes.NewBuffer(bodyBytes))

var statusFromMsg int
statusFromMsg := 0
err = next(c)

status := c.Response().Status
Expand Down Expand Up @@ -73,7 +73,21 @@ func Retry(config *config.Config) echo.MiddlewareFunc {

err = next(c)
// Log the status after the retry attempt
c.Logger().Infof("Retry attempt status: %d", c.Response().Status)
c.Logger().Infof("Retry attempt http status: %d", c.Response().Status)
// Extract the status code from the response body for the retry attempt
statusFromMsgRetry := 0
if err != nil {
match := statusCodeRegex.FindStringSubmatch(err.Error())
if len(match) > 1 {
statusFromMsgRetry, _ = strconv.Atoi(match[1])
}
}
retryFailed := statusFromMsgRetry == 502 || c.Response().Status == http.StatusNotFound || c.Response().Status == http.StatusForbidden
if retryFailed {
c.Logger().Infof("Retry attempt http status: %d, code found in body: %d", c.Response().Status, statusFromMsgRetry)
} else {
c.Logger().Infof("Retry attempt succeeded with http status: %d, code found in body: %d", c.Response().Status, statusFromMsgRetry)
}
}

c.Set("retry", nil)
Expand Down

0 comments on commit e3d7d98

Please sign in to comment.