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 <noreply@anthropic.com>
This commit is contained in:
Doug Borg
2026-02-08 11:17:29 -07:00
committed by Doug Borg
parent 71776ee8f0
commit 5abcc58a78
2 changed files with 19 additions and 2 deletions

View File

@@ -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<RouteResult> 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}');
}

View File

@@ -376,4 +376,10 @@ class NavigationState extends ChangeNotifier {
notifyListeners();
}
}
@override
void dispose() {
_routingService.close();
super.dispose();
}
}