diff --git a/rest/controllers/coolify_controller.go b/rest/controllers/coolify_controller.go index 1cf4dfe..18cd072 100644 --- a/rest/controllers/coolify_controller.go +++ b/rest/controllers/coolify_controller.go @@ -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))