fix: Remove mock data fallback in production for better error visibility
- Removed mock data fallback from /signals endpoint - Now returns HTTP 503 with clear error messages when protocol servers are unavailable - Protocol servers are disabled in production, so dashboard will show clear error messages - This ensures we can properly test connectivity issues and don't mask real problems
This commit is contained in:
parent
98a3254c88
commit
26bcc8d83f
|
|
@ -622,7 +622,7 @@ async def get_signals():
|
|||
|
||||
# Check if protocol servers are enabled before trying to connect
|
||||
if settings.opcua_enabled or settings.modbus_enabled:
|
||||
# Try to get data from protocol servers, fallback to mock data if servers are not available
|
||||
# Try to get data from protocol servers
|
||||
try:
|
||||
# Initialize protocol data collector
|
||||
from src.dashboard.protocol_clients import ProtocolDataCollector
|
||||
|
|
@ -642,18 +642,26 @@ async def get_signals():
|
|||
# Clean up connections
|
||||
await collector.cleanup()
|
||||
|
||||
# If no signals were retrieved from protocol servers, use mock data
|
||||
# If no signals were retrieved from protocol servers, return error
|
||||
if not signals:
|
||||
logger.warning("no_signals_from_protocol_servers", fallback="using_mock_data")
|
||||
signals = await _generate_mock_signals(stations, pumps_by_station)
|
||||
logger.error("no_signals_from_protocol_servers")
|
||||
raise HTTPException(
|
||||
status_code=503,
|
||||
detail="No signals available from protocol servers. Please check server connectivity."
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error("failed_to_get_protocol_data", error=str(e), fallback="using_mock_data")
|
||||
# Fallback to mock data
|
||||
signals = await _generate_mock_signals(stations, pumps_by_station)
|
||||
logger.error("failed_to_get_protocol_data", error=str(e))
|
||||
raise HTTPException(
|
||||
status_code=503,
|
||||
detail=f"Unable to connect to protocol servers: {str(e)}"
|
||||
)
|
||||
else:
|
||||
# Protocol servers are disabled, use mock data
|
||||
logger.info("protocol_servers_disabled", fallback="using_mock_data")
|
||||
signals = await _generate_mock_signals(stations, pumps_by_station)
|
||||
# Protocol servers are disabled, return clear error
|
||||
logger.error("protocol_servers_disabled_in_production")
|
||||
raise HTTPException(
|
||||
status_code=503,
|
||||
detail="Protocol servers are disabled in production environment. No real-time data available."
|
||||
)
|
||||
|
||||
# Add system status signals
|
||||
signals.extend([
|
||||
|
|
|
|||
Loading…
Reference in New Issue