From 5abcc58a78d51a610ebca871e11dbfa7731c9931 Mon Sep 17 00:00:00 2001 From: Doug Borg Date: Sun, 8 Feb 2026 11:17:29 -0700 Subject: [PATCH] Address PR review: truncate error response logs and close http client - Gate full error response body logging behind kDebugMode; truncate to 500 chars in release builds to avoid log noise and data exposure - Add RoutingService.close() and call from NavigationState.dispose() Co-Authored-By: Claude Opus 4.6 --- lib/services/routing_service.dart | 15 +++++++++++++-- lib/state/navigation_state.dart | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/services/routing_service.dart b/lib/services/routing_service.dart index 3fa6f82..af0b8b3 100644 --- a/lib/services/routing_service.dart +++ b/lib/services/routing_service.dart @@ -30,7 +30,9 @@ class RoutingService { final http.Client _client; RoutingService({http.Client? client}) : _client = client ?? http.Client(); - + + void close() => _client.close(); + // Calculate route between two points using alprwatch Future calculateRoute({ required LatLng start, @@ -80,7 +82,16 @@ class RoutingService { ).timeout(kNavigationRoutingTimeout); if (response.statusCode != 200) { - debugPrint('[RoutingService] Error response body: ${response.body}'); + if (kDebugMode) { + debugPrint('[RoutingService] Error response body: ${response.body}'); + } else { + const maxLen = 500; + final body = response.body; + final truncated = body.length > maxLen + ? '${body.substring(0, maxLen)}… [truncated]' + : body; + debugPrint('[RoutingService] Error response body ($maxLen char max): $truncated'); + } throw RoutingException('HTTP ${response.statusCode}: ${response.reasonPhrase}'); } diff --git a/lib/state/navigation_state.dart b/lib/state/navigation_state.dart index f87ebea..feb090d 100644 --- a/lib/state/navigation_state.dart +++ b/lib/state/navigation_state.dart @@ -376,4 +376,10 @@ class NavigationState extends ChangeNotifier { notifyListeners(); } } + + @override + void dispose() { + _routingService.close(); + super.dispose(); + } }