Skip to content

fix: show accurate error messages when API fails with device online - #3592

Merged
Baalmart merged 1 commit into
stagingfrom
fix/misleading-error-messages
Jun 8, 2026
Merged

fix: show accurate error messages when API fails with device online#3592
Baalmart merged 1 commit into
stagingfrom
fix/misleading-error-messages

Conversation

@Mozart299

@Mozart299 Mozart299 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor
  • 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

Summary by CodeRabbit

  • Bug Fixes
    • Error messages and icons now differentiate between offline connectivity issues and other errors across multiple screens
    • Offline status is tracked and displayed throughout the app's dashboard, lessons, and map views
    • Increased timeout for language model downloads to reduce premature failure errors

- 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
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds offline status detection across the mobile app. Dashboard, Learn, and Map screens now detect connection status via CacheManager and display conditional error UIs—showing offline-specific icons and messages when disconnected, versus generic error messaging otherwise. Language selection also improves with a longer timeout and more granular error classification.

Changes

Offline status detection and conditional error messaging

Layer / File(s) Summary
Learn feature offline detection
src/mobile/lib/src/app/learn/bloc/kya_state.dart, src/mobile/lib/src/app/learn/bloc/kya_bloc.dart, src/mobile/lib/src/app/learn/pages/kya_page.dart
LessonsLoadingError adds an isOffline field; KyaBloc creates a CacheManager instance and sets isOffline: !_cacheManager.isConnected in error states emitted from _onLoadLessons and _onRefreshLessons; KyaPage renders conditional error icons (cloud-off when offline, error-outline otherwise) and conditional messages (connection-specific prompt vs generic failure).
Map feature offline detection
src/mobile/lib/src/app/map/widgets/map_error_view.dart, src/mobile/lib/src/app/map/pages/map_page.dart
MapErrorView adds an isOffline input parameter (defaulting to false) and switches the error icon and message based on offline status; MapPage imports CacheManager, passes isOffline to MapErrorView based on connection status, and adds explicit MapLoadingError handling in the MapBloc listener to clear loading state.
Dashboard offline detection
src/mobile/lib/src/app/dashboard/pages/dashboard_page.dart
DashboardPage error UI now conditionally renders the error icon (cloud-off vs error-outline) and messages (check connection vs generic failure) based on state.isOffline.
Language selection error handling
src/mobile/lib/src/app/profile/pages/languages/select_language_page.dart
ML Kit model download timeout increased from 30 seconds to 3 minutes; exception handler now differentiates SocketException (network/offline message), TimeoutException (download taking too long), and other errors with appropriate user-facing messaging.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

mobile-app

Suggested reviewers

  • Baalmart

Poem

A cloud of errors no more appears the same,
When offline winds blow, a new icon takes aim,
Dashboard, Map, and Learn now speak truth clear—
"No connection?" we whisper, "Let's wait right here." ☁️🔄

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the changeset: distinguishing between actual offline errors and API failures to show appropriate error messages.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/misleading-error-messages

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/mobile/lib/src/app/map/pages/map_page.dart (1)

389-389: ⚡ Quick win

Consider the timing of the offline status check.

The offline check !CacheManager().isConnected happens at render time (in the build method) 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
  1. Add an isOffline field to MapLoadingError state (similar to LessonsLoadingError)
  2. Have MapBloc check CacheManager().isConnected when emitting the error state
  3. Update this line to read isOffline: state.isOffline instead of inline checking

This 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

📥 Commits

Reviewing files that changed from the base of the PR and between 568c743 and 9a5bfc4.

📒 Files selected for processing (7)
  • src/mobile/lib/src/app/dashboard/pages/dashboard_page.dart
  • src/mobile/lib/src/app/learn/bloc/kya_bloc.dart
  • src/mobile/lib/src/app/learn/bloc/kya_state.dart
  • src/mobile/lib/src/app/learn/pages/kya_page.dart
  • src/mobile/lib/src/app/map/pages/map_page.dart
  • src/mobile/lib/src/app/map/widgets/map_error_view.dart
  • src/mobile/lib/src/app/profile/pages/languages/select_language_page.dart

@Mozart299
Mozart299 requested a review from Baalmart June 8, 2026 12:11
@Baalmart
Baalmart merged commit f2bc41d into staging Jun 8, 2026
25 of 27 checks passed
@Baalmart
Baalmart deleted the fix/misleading-error-messages branch June 8, 2026 13:13
@Baalmart Baalmart mentioned this pull request Jun 8, 2026
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants