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:
11
app.py
11
app.py
@@ -181,7 +181,7 @@ def api_network():
|
||||
try:
|
||||
return jsonify(json.loads(raw))
|
||||
except Exception:
|
||||
pass
|
||||
logger.error('Failed to parse network_snapshot JSON')
|
||||
return jsonify({'hosts': {}, 'unifi': [], 'updated': None})
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ def api_links():
|
||||
try:
|
||||
return jsonify(json.loads(raw))
|
||||
except Exception:
|
||||
pass
|
||||
logger.error('Failed to parse link_stats JSON')
|
||||
return jsonify({'hosts': {}, 'updated': None})
|
||||
|
||||
|
||||
@@ -261,9 +261,12 @@ def api_diagnose_start():
|
||||
"""Start a link diagnostic job. Returns {job_id}."""
|
||||
data = request.get_json(silent=True) or {}
|
||||
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
|
||||
|
||||
# Look up switch + port in cached link_stats
|
||||
|
||||
Reference in New Issue
Block a user