fix: coolify proxy no retorna 502 para evitar intercepción de Cloudflare

Cambia StatusBadGateway (502) → StatusBadRequest (400) en todos los
errores del proxy Coolify. Cloudflare intercepta respuestas 502 del
origen y muestra su propia pantalla, ocultando el error al frontend.
Con 400, el JSON de error llega al cliente y Alpine.js puede mostrarlo.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Lizandro Guarnizo
2026-05-25 21:40:09 -05:00
co-authored by Copilot
parent e1aba741a7
commit 7bfe7cba5c
+7 -2
View File
@@ -54,12 +54,17 @@ func coolifyProxy(c *fiber.Ctx, method, endpoint string) error {
}
body, status, err := coolifyDo(method, ep, bodyReader, ct, cfg)
if err != nil {
return c.Status(fiber.StatusBadGateway).JSON(fiber.Map{"error": err.Error()})
// No devolver 502: Cloudflare lo intercepta y oculta el error al frontend
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "No se pudo conectar a Coolify: " + err.Error()})
}
var result json.RawMessage
if err := json.Unmarshal(body, &result); err != nil {
result = json.RawMessage(fmt.Sprintf(`{"raw":%q}`, string(body)))
}
// Si Coolify devuelve 5xx, bajar a 400 para que Cloudflare no lo intercepte
if status >= 500 {
status = fiber.StatusBadRequest
}
c.Status(status)
return c.JSON(result)
}
@@ -122,7 +127,7 @@ func CoolifyTestConnection(c *fiber.Ctx) error {
client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Get(base + "/api/health")
if err != nil {
return c.Status(fiber.StatusBadGateway).JSON(fiber.Map{"error": err.Error()})
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "No se pudo conectar a Coolify: " + err.Error()})
}
defer resp.Body.Close()
body, _ := io.ReadAll(io.LimitReader(resp.Body, 64*1024))