Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Handling for urlConnection #2902

Merged

Conversation

anandwana001
Copy link
Collaborator

@anandwana001 anandwana001 commented Dec 9, 2024

Fixes #2683
Fixes #662

@shobhitagarwal1612 PTAL?

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 15.38462% with 22 lines in your changes missing coverage. Please review.

Project coverage is 62.87%. Comparing base (102e87d) to head (1dabbe2).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...lineareas/selector/OfflineAreaSelectorViewModel.kt 5.88% 16 Missing ⚠️
...flineareas/selector/OfflineAreaSelectorFragment.kt 37.50% 1 Missing and 4 partials ⚠️
...android/ground/repository/OfflineAreaRepository.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2902      +/-   ##
============================================
- Coverage     62.97%   62.87%   -0.11%     
- Complexity     1287     1288       +1     
============================================
  Files           273      273              
  Lines          6723     6739      +16     
  Branches        933      937       +4     
============================================
+ Hits           4234     4237       +3     
- Misses         1872     1882      +10     
- Partials        617      620       +3     
Files with missing lines Coverage Δ
...le/android/ground/ui/map/gms/mog/UrlInputStream.kt 0.00% <ø> (ø)
...android/ground/repository/OfflineAreaRepository.kt 49.18% <0.00%> (ø)
...flineareas/selector/OfflineAreaSelectorFragment.kt 35.00% <37.50%> (-0.19%) ⬇️
...lineareas/selector/OfflineAreaSelectorViewModel.kt 28.72% <5.88%> (-2.23%) ⬇️

@gino-m
Copy link
Collaborator

gino-m commented Dec 12, 2024

We should handle the error upstream where it can actually be addressed:

viewModelScope.launch(ioDispatcher) {
offlineAreaRepository.downloadTiles(viewport!!).collect { (bytesDownloaded, totalBytes) ->
val progressValue =
if (totalBytes > 0) {
(bytesDownloaded.toFloat() / totalBytes.toFloat()).coerceIn(0f, 1f)
} else {
0f
}
downloadProgress.postValue(progressValue)
}
isDownloadProgressVisible.postValue(false)
_navigate.emit(UiState.OfflineAreaBackToHomeScreen)
}
}

You would add .catch{} before collect to handle the failure (show a toast and close the dialog).

gino-m
gino-m previously requested changes Dec 16, 2024
Copy link
Collaborator

@gino-m gino-m left a comment

Choose a reason for hiding this comment

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

Thanks! A few requests, LG

anandwana001 and others added 12 commits December 17, 2024 12:32
…-timeout-exception' into anandwana001/2683/prevent-socket-timeout-exception
…xception

# Conflicts:
#	app/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragment.kt
#	app/src/test/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModelTest.kt
…xception

# Conflicts:
#	app/src/main/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorViewModel.kt
#	app/src/test/java/com/google/android/ground/ui/offlineareas/selector/OfflineAreaSelectorFragmentTest.kt
@shobhitagarwal1612 shobhitagarwal1612 merged commit 8d453f3 into master Feb 7, 2025
5 checks passed
@shobhitagarwal1612 shobhitagarwal1612 deleted the anandwana001/2683/prevent-socket-timeout-exception branch February 7, 2025 10:18
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.

App Crash - While Downloading Area [Offline basemap download] Handle edge cases when offline
4 participants