Fix port_idx type coercion and add logging to silent except blocks

- port_idx now coerced to int() with 400 on invalid type (prevents string/int mismatch)
- api_network and api_links bare except blocks now log errors instead of silently passing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-12 17:35:41 -04:00
parent 0335845101
commit f8395dcd24

11
app.py
View File

@@ -181,7 +181,7 @@ def api_network():
try: try:
return jsonify(json.loads(raw)) return jsonify(json.loads(raw))
except Exception: except Exception:
pass logger.error('Failed to parse network_snapshot JSON')
return jsonify({'hosts': {}, 'unifi': [], 'updated': None}) return jsonify({'hosts': {}, 'unifi': [], 'updated': None})
@@ -193,7 +193,7 @@ def api_links():
try: try:
return jsonify(json.loads(raw)) return jsonify(json.loads(raw))
except Exception: except Exception:
pass logger.error('Failed to parse link_stats JSON')
return jsonify({'hosts': {}, 'updated': None}) return jsonify({'hosts': {}, 'updated': None})
@@ -261,9 +261,12 @@ def api_diagnose_start():
"""Start a link diagnostic job. Returns {job_id}.""" """Start a link diagnostic job. Returns {job_id}."""
data = request.get_json(silent=True) or {} data = request.get_json(silent=True) or {}
switch_name = (data.get('switch_name') or '').strip() switch_name = (data.get('switch_name') or '').strip()
port_idx = data.get('port_idx') try:
port_idx = int(data.get('port_idx'))
except (TypeError, ValueError):
return jsonify({'error': 'port_idx must be an integer'}), 400
if not switch_name or port_idx is None: if not switch_name:
return jsonify({'error': 'switch_name and port_idx required'}), 400 return jsonify({'error': 'switch_name and port_idx required'}), 400
# Look up switch + port in cached link_stats # Look up switch + port in cached link_stats