Files
intercept/utils/responses.py
Smittix 90281b1535 fix(modes): deep-linked mode scripts fail when body not yet parsed
ensureModeScript() used document.body.appendChild() to load lazy mode
scripts, but the preload for ?mode= query params runs in <head> before
<body> exists, causing all deep-linked modes to silently fail.

Also fix cross-mode handoffs (BT→BT Locate, WiFi→WiFi Locate,
Spy Stations→Waterfall) that assumed target module was already loaded.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 20:49:08 +00:00

38 lines
1.1 KiB
Python

"""Standardized API response helpers.
Use these in new or modified routes for consistent JSON responses.
Existing routes are NOT being refactored to avoid unnecessary churn.
"""
from flask import jsonify
def api_success(data=None, message=None, status_code=200):
"""Return a success JSON response.
Args:
data: Optional dict of additional fields merged into the response.
message: Optional human-readable message.
status_code: HTTP status code (default 200).
"""
payload = {'status': 'success'}
if message:
payload['message'] = message
if data:
payload.update(data)
return jsonify(payload), status_code
def api_error(message, status_code=400, error_type=None):
"""Return an error JSON response.
Args:
message: Human-readable error message.
status_code: HTTP status code (default 400).
error_type: Optional machine-readable error category (e.g. 'DEVICE_BUSY').
"""
payload = {'status': 'error', 'message': message}
if error_type:
payload['error_type'] = error_type
return jsonify(payload), status_code