Nivel 129: demo_level129.py
Este es el nivel 129 del tour de aprendizaje.
Código Fuente
"""
DEMO LEVEL 129: API Error Handling
----------------------------------
Adds: Manejo de errores de API.
Continues: L128.
DIAGRAM:
try/except en llamadas API
"""
from wpipe.api_client import APIClient
if __name__ == "__main__":
print(">>> API error handling...")
client = APIClient(base_url="https://nonexistent.example.com")
try:
print("⚠️ Intentando conexión...")
result = client.send_get("/test")
except Exception as e:
print(f"❌ Error capturado: {type(e).__name__}")
print("✅ Sistema tolerante a errores")
Resultado de Ejecución
>>> API error handling...
⚠️ Intentando conexión...
✅ Sistema tolerante a errores
Error in GET request to https://nonexistent.example.com/test: HTTPSConnectionPool(host='nonexistent.example.com', port=443): Max retries exceeded with url: /test (Caused by NameResolutionError("HTTPSConnection(host='nonexistent.example.com', port=443): Failed to resolve 'nonexistent.example.com' ([Errno -5] No address associated with hostname)"))