fix: show accurate error messages when API fails with device online - #3592
Conversation
- Dashboard, map, and KYA screens were showing "Couldn't connect to the internet" / cloud_off icon for all errors including API 401/500, not just actual connectivity failures - Map page was stuck on loading spinner forever when MapLoadingError was emitted (isInitializing never cleared on error) - Add isOffline flag to LessonsLoadingError state so KYA page can differentiate connectivity vs API errors - Increase ML Kit model download timeout from 30s to 3 minutes; distinguish TimeoutException from SocketException in error copy
📝 WalkthroughWalkthroughThe PR adds offline status detection across the mobile app. Dashboard, Learn, and Map screens now detect connection status via ChangesOffline status detection and conditional error messaging
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/mobile/lib/src/app/map/pages/map_page.dart (1)
389-389: ⚡ Quick winConsider the timing of the offline status check.
The offline check
!CacheManager().isConnectedhappens at render time (in thebuildmethod) rather than at the moment the error occurred. If connectivity changes between when the error was emitted and when the UI renders, the displayed error state might not accurately reflect the conditions that caused the failure.Consider capturing the offline status at error time within the MapBloc (similar to the Learn bloc pattern) and passing it through the state, rather than checking it during render.
♻️ Suggested approach
- Add an
isOfflinefield toMapLoadingErrorstate (similar toLessonsLoadingError)- Have
MapBloccheckCacheManager().isConnectedwhen emitting the error state- Update this line to read
isOffline: state.isOfflineinstead of inline checkingThis would make the map feature consistent with the learn feature implementation and ensure offline status is captured at error time.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/mobile/lib/src/app/map/pages/map_page.dart` at line 389, The MapErrorView is using CacheManager().isConnected at build time which can differ from connectivity when the error occurred; update MapBloc to capture connectivity when emitting the error by adding an isOffline boolean to the MapLoadingError state (mirror LessonsLoadingError), set isOffline = !CacheManager().isConnected inside the error-emission logic in MapBloc, and then change the widget instantiation to pass isOffline: state.isOffline (keep onRetry: _retryLoading and MapErrorView as-is) so the UI reflects the error-time offline status.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/mobile/lib/src/app/map/pages/map_page.dart`:
- Line 389: The MapErrorView is using CacheManager().isConnected at build time
which can differ from connectivity when the error occurred; update MapBloc to
capture connectivity when emitting the error by adding an isOffline boolean to
the MapLoadingError state (mirror LessonsLoadingError), set isOffline =
!CacheManager().isConnected inside the error-emission logic in MapBloc, and then
change the widget instantiation to pass isOffline: state.isOffline (keep
onRetry: _retryLoading and MapErrorView as-is) so the UI reflects the error-time
offline status.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 842f6a04-3ec5-4650-bc5b-6180e71f91e8
📒 Files selected for processing (7)
src/mobile/lib/src/app/dashboard/pages/dashboard_page.dartsrc/mobile/lib/src/app/learn/bloc/kya_bloc.dartsrc/mobile/lib/src/app/learn/bloc/kya_state.dartsrc/mobile/lib/src/app/learn/pages/kya_page.dartsrc/mobile/lib/src/app/map/pages/map_page.dartsrc/mobile/lib/src/app/map/widgets/map_error_view.dartsrc/mobile/lib/src/app/profile/pages/languages/select_language_page.dart
Summary by CodeRabbit