Merge branch 'copilot/vcard-api-integraciones-anlisis'
This commit is contained in:
@@ -54,12 +54,17 @@ func coolifyProxy(c *fiber.Ctx, method, endpoint string) error {
|
|||||||
}
|
}
|
||||||
body, status, err := coolifyDo(method, ep, bodyReader, ct, cfg)
|
body, status, err := coolifyDo(method, ep, bodyReader, ct, cfg)
|
||||||
if err != nil {
|
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
|
var result json.RawMessage
|
||||||
if err := json.Unmarshal(body, &result); err != nil {
|
if err := json.Unmarshal(body, &result); err != nil {
|
||||||
result = json.RawMessage(fmt.Sprintf(`{"raw":%q}`, string(body)))
|
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)
|
c.Status(status)
|
||||||
return c.JSON(result)
|
return c.JSON(result)
|
||||||
}
|
}
|
||||||
@@ -122,7 +127,7 @@ func CoolifyTestConnection(c *fiber.Ctx) error {
|
|||||||
client := &http.Client{Timeout: 10 * time.Second}
|
client := &http.Client{Timeout: 10 * time.Second}
|
||||||
resp, err := client.Get(base + "/api/health")
|
resp, err := client.Get(base + "/api/health")
|
||||||
if err != nil {
|
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()
|
defer resp.Body.Close()
|
||||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 64*1024))
|
body, _ := io.ReadAll(io.LimitReader(resp.Body, 64*1024))
|
||||||
|
|||||||
Reference in New Issue
Block a user