Compare commits

...

2 Commits

2 changed files with 15 additions and 1 deletions
+8
View File
@@ -2,6 +2,7 @@ package main
import (
"crypto/tls"
"fmt"
"time"
fiber "github.com/gofiber/fiber/v2"
@@ -38,12 +39,19 @@ func proxyTheRequest(c *fiber.Ctx) error {
proxy.WithClient(cfg.Client.FastProxyClient)
cfg.Logger.Debug("Proxying the request", map[string]interface{}{"path": c.Path(), "body": string(c.Request().Body())})
err := proxy.DoRedirects(c, cfg.Server.HostGraphQL+c.Path(), 3)
if err != nil {
cfg.Logger.Error("Can't proxy the request", map[string]interface{}{"error": err.Error()})
cfg.Monitoring.Increment(libpack_monitoring.MetricsFailed, nil)
return err
}
cfg.Logger.Debug("Received proxied response", map[string]interface{}{"path": c.Path(), "response_body": string(c.Response().Body()), "response_code": c.Response().StatusCode()})
if c.Response().StatusCode() != 200 {
cfg.Monitoring.Increment(libpack_monitoring.MetricsFailed, nil)
return fmt.Errorf("Received non-200 response from the GraphQL server: %d", c.Response().StatusCode())
}
c.Response().Header.Del(fiber.HeaderServer)
return nil
+7 -1
View File
@@ -127,7 +127,13 @@ func processGraphQLRequest(c *fiber.Ctx) error {
// Additional helper function to avoid code repetition
func proxyAndCacheTheRequest(c *fiber.Ctx, queryCacheHash string, cache_time int) {
proxyTheRequest(c)
err := proxyTheRequest(c)
if err != nil {
cfg.Logger.Error("Can't proxy the request", map[string]interface{}{"error": err.Error()})
cfg.Monitoring.Increment(libpack_monitoring.MetricsFailed, nil)
c.Status(500).SendString("Can't proxy the request - try again later")
return
}
cfg.Cache.CacheClient.Set(queryCacheHash, c.Response().Body(), time.Duration(cache_time)*time.Second)
c.Send(c.Response().Body())
}