Files
whatsapp/diagnose_fetch_errors.sh
T
2026-01-27 14:51:41 -05:00

122 lines
3.8 KiB
Bash
Executable File

#!/bin/bash
# Script de diagnóstico para errores de fetch
# Fecha: 27 de enero de 2026
echo "🔍 Diagnóstico de errores 'Failed to fetch'"
echo "============================================"
echo ""
BASE_URL="http://localhost:8000"
# Colores
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo "📍 Base URL: $BASE_URL"
echo ""
# Test 1: Verificar que los endpoints existan
echo "1️⃣ Verificando endpoints..."
if [ -f "api/get_conversations.php" ]; then
echo -e " ${GREEN}${NC} api/get_conversations.php existe"
else
echo -e " ${RED}${NC} api/get_conversations.php NO existe"
fi
if [ -f "api/get_notifications.php" ]; then
echo -e " ${GREEN}${NC} api/get_notifications.php existe"
else
echo -e " ${RED}${NC} api/get_notifications.php NO existe"
fi
echo ""
# Test 2: Verificar sintaxis PHP
echo "2️⃣ Verificando sintaxis PHP..."
if php -l api/get_conversations.php > /dev/null 2>&1; then
echo -e " ${GREEN}${NC} get_conversations.php sintaxis correcta"
else
echo -e " ${RED}${NC} get_conversations.php tiene errores de sintaxis"
php -l api/get_conversations.php
fi
if php -l api/get_notifications.php > /dev/null 2>&1; then
echo -e " ${GREEN}${NC} get_notifications.php sintaxis correcta"
else
echo -e " ${RED}${NC} get_notifications.php tiene errores de sintaxis"
php -l api/get_notifications.php
fi
echo ""
# Test 3: Verificar servidor PHP
echo "3️⃣ Verificando servidor PHP..."
if curl -s "$BASE_URL" > /dev/null 2>&1; then
echo -e " ${GREEN}${NC} Servidor PHP respondiendo en $BASE_URL"
else
echo -e " ${RED}${NC} Servidor PHP NO responde en $BASE_URL"
echo " Inicia el servidor con: php -S localhost:8000"
fi
echo ""
# Test 4: Verificar que config.php exista
echo "4️⃣ Verificando configuración..."
if [ -f "config/config.php" ]; then
echo -e " ${GREEN}${NC} config/config.php existe"
else
echo -e " ${RED}${NC} config/config.php NO existe"
fi
echo ""
# Test 5: Intentar acceder a los endpoints (sin autenticación)
echo "5️⃣ Probando acceso a endpoints..."
RESP=$(curl -s -o /dev/null -w "%{http_code}" "$BASE_URL/api/get_conversations.php")
if [ "$RESP" = "200" ]; then
echo -e " ${GREEN}${NC} get_conversations.php responde 200"
elif [ "$RESP" = "401" ]; then
echo -e " ${YELLOW}${NC} get_conversations.php requiere autenticación (401)"
else
echo -e " ${RED}${NC} get_conversations.php responde $RESP"
fi
RESP=$(curl -s -o /dev/null -w "%{http_code}" "$BASE_URL/api/get_notifications.php")
if [ "$RESP" = "200" ]; then
echo -e " ${GREEN}${NC} get_notifications.php responde 200"
elif [ "$RESP" = "401" ]; then
echo -e " ${YELLOW}${NC} get_notifications.php requiere autenticación (401)"
else
echo -e " ${RED}${NC} get_notifications.php responde $RESP"
fi
echo ""
# Test 6: Verificar logs de error
echo "6️⃣ Revisando logs de error recientes..."
if [ -f "/tmp/php_errors.log" ]; then
echo " Últimas 5 líneas del log:"
tail -5 /tmp/php_errors.log 2>/dev/null || echo " No se pudieron leer los logs"
else
echo " No se encontró archivo de log en /tmp/php_errors.log"
fi
echo ""
echo "============================================"
echo "✅ Diagnóstico completo"
echo ""
echo "📌 Soluciones comunes:"
echo " 1. Si los endpoints requieren autenticación (401):"
echo " - Asegúrate de estar logueado en conversations.php"
echo " - Verifica que las cookies de sesión se envíen"
echo ""
echo " 2. Si el servidor no responde:"
echo " - Inicia: cd /Users/lizandro/Documents/GitHub/whatsapp && php -S localhost:8000"
echo ""
echo " 3. Si hay errores de sintaxis:"
echo " - Revisa el archivo indicado y corrige los errores"
echo ""
echo " 4. Para ver errores en tiempo real:"
echo " - tail -f /tmp/php_errors.log"
echo ""