From c82fb9f3343467ceb0fa71331fbf37d89ed083af Mon Sep 17 00:00:00 2001 From: MarekWo Date: Mon, 23 Mar 2026 10:32:56 +0100 Subject: [PATCH] fix(paths): fix reset_flood endpoint error handling and add logging Endpoint now returns error if device reset fails instead of always returning success:true. Added logging to both endpoint and device_manager.reset_path to diagnose reset failures. Co-Authored-By: Claude Opus 4.6 --- app/device_manager.py | 4 +++- app/routes/api.py | 22 +++++++++------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/app/device_manager.py b/app/device_manager.py index e393414..934b97f 100644 --- a/app/device_manager.py +++ b/app/device_manager.py @@ -1369,7 +1369,9 @@ class DeviceManager: return {'success': False, 'error': 'Device not connected'} try: - self.execute(self.mc.commands.reset_path(pubkey)) + logger.info(f"Executing reset_path for {pubkey[:12]}...") + result = self.execute(self.mc.commands.reset_path(pubkey)) + logger.info(f"reset_path result: {result}") return {'success': True, 'message': 'Path reset'} except Exception as e: logger.error(f"Failed to reset path: {e}") diff --git a/app/routes/api.py b/app/routes/api.py index 7b64636..cdd0b34 100644 --- a/app/routes/api.py +++ b/app/routes/api.py @@ -2315,20 +2315,16 @@ def reorder_contact_paths(pubkey): def reset_contact_to_flood(pubkey): """Reset device path to FLOOD mode (does not delete configured paths).""" try: - result = {'success': True} - try: - dm = cli.get_device_manager() - if dm and dm.is_connected: - dev_result = dm.reset_path(pubkey) - result['device_reset'] = dev_result.get('success', False) - else: - result['device_reset'] = False - result['warning'] = 'Device not connected' - except Exception as e: - result['device_reset'] = False - result['warning'] = f'Device reset failed: {e}' - return jsonify(result), 200 + dm = cli.get_device_manager() + if not dm or not dm.is_connected: + return jsonify({'success': False, 'error': 'Device not connected'}), 503 + dev_result = dm.reset_path(pubkey) + logger.info(f"reset_path({pubkey[:12]}...) result: {dev_result}") + if dev_result.get('success'): + return jsonify({'success': True}), 200 + return jsonify({'success': False, 'error': dev_result.get('error', 'Device reset failed')}), 500 except Exception as e: + logger.error(f"reset_flood error: {e}") return jsonify({'success': False, 'error': str(e)}), 500