From cdd2a2a2c64fd0c6ff17159dc756e583d27c0721 Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Tue, 20 Aug 2024 12:45:22 +0100 Subject: [PATCH] Enhance the retry logic for the proxied queries. --- proxy.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/proxy.go b/proxy.go index 57b9505..2f9e90e 100644 --- a/proxy.go +++ b/proxy.go @@ -57,20 +57,29 @@ func proxyTheRequest(c *fiber.Ctx, currentEndpoint string) error { err = retry.Do( func() error { - return proxy.DoRedirects(c, proxyURL, 3, cfg.Client.FastProxyClient) + proxyErr := proxy.DoRedirects(c, proxyURL, 3, cfg.Client.FastProxyClient) + if proxyErr != nil { + return proxyErr + } + if c.Response().StatusCode() != 200 { + return fmt.Errorf("received non-200 response from the GraphQL server: %d", c.Response().StatusCode()) + } + return nil }, + retry.Attempts(5), + retry.DelayType(retry.BackOffDelay), + retry.Delay(250*time.Millisecond), + retry.MaxDelay(5*time.Second), retry.OnRetry(func(n uint, err error) { cfg.Logger.Warning(&libpack_logger.LogMessage{ Message: "Retrying the request", Pairs: map[string]interface{}{ - "path": c.Path(), - "error": err.Error(), + "path": c.Path(), + "attempt": n + 1, + "error": err.Error(), }, }) }), - retry.Attempts(3), - retry.DelayType(retry.BackOffDelay), - retry.Delay(250*time.Millisecond), retry.LastErrorOnly(true), )