File tree Expand file tree Collapse file tree 3 files changed +17
-14
lines changed
desktop/src/main/kotlin/com/jdamcd/arrivals/desktop
shared/src/commonMain/kotlin/com/jdamcd/arrivals Expand file tree Collapse file tree 3 files changed +17
-14
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import androidx.lifecycle.ViewModel
4
4
import androidx.lifecycle.viewModelScope
5
5
import com.jdamcd.arrivals.Arrivals
6
6
import com.jdamcd.arrivals.ArrivalsInfo
7
+ import com.jdamcd.arrivals.NoDataException
7
8
import kotlinx.coroutines.Job
8
9
import kotlinx.coroutines.delay
9
10
import kotlinx.coroutines.flow.MutableStateFlow
@@ -43,9 +44,11 @@ class ArrivalsViewModel(private val arrivals: Arrivals) : ViewModel() {
43
44
try {
44
45
val result = arrivals.latest()
45
46
_uiState .value = ArrivalsState .Data (result, false )
47
+ } catch (e: NoDataException ) {
48
+ _uiState .value = ArrivalsState .Error (e.message ? : " Unknown error" )
46
49
} catch (e: Exception ) {
47
50
if (_uiState .value !is ArrivalsState .Data ) {
48
- _uiState .value = ArrivalsState .Error (e.message ? : " Unknown error" )
51
+ _uiState .value = ArrivalsState .Error (" Unknown error" )
49
52
}
50
53
}
51
54
}
Original file line number Diff line number Diff line change @@ -23,16 +23,16 @@ internal class GtfsArrivals(
23
23
@Throws(NoDataException ::class , CancellationException ::class )
24
24
override suspend fun latest (): ArrivalsInfo {
25
25
updateStops()
26
+ val model: ArrivalsInfo
26
27
try {
27
- val model = formatArrivals(api.fetchFeedMessage(settings.gtfsRealtime))
28
- if (model.arrivals.isNotEmpty()) {
29
- return model
30
- } else {
31
- throw NoDataException (" No arrivals found" )
32
- }
28
+ model = formatArrivals(api.fetchFeedMessage(settings.gtfsRealtime))
33
29
} catch (e: Exception ) {
34
- throw NoDataException (" Failed to connect" )
30
+ throw NoDataException (" No connection" )
31
+ }
32
+ if (model.arrivals.isEmpty()) {
33
+ throw NoDataException (" No arrivals found" )
35
34
}
35
+ return model
36
36
}
37
37
38
38
private suspend fun updateStops () {
Original file line number Diff line number Diff line change @@ -20,16 +20,16 @@ internal class TflArrivals(
20
20
21
21
@Throws(NoDataException ::class , CancellationException ::class )
22
22
override suspend fun latest (): ArrivalsInfo {
23
+ val model: ArrivalsInfo
23
24
try {
24
- val model = formatArrivals(api.fetchArrivals(settings.tflStopId))
25
- if (model.arrivals.isNotEmpty()) {
26
- return model
27
- } else {
28
- throw NoDataException (" No arrivals found" )
29
- }
25
+ model = formatArrivals(api.fetchArrivals(settings.tflStopId))
30
26
} catch (e: Exception ) {
31
27
throw NoDataException (" No connection" )
32
28
}
29
+ if (model.arrivals.isEmpty()) {
30
+ throw NoDataException (" No arrivals found" )
31
+ }
32
+ return model
33
33
}
34
34
35
35
@Throws(CancellationException ::class )
You can’t perform that action at this time.
0 commit comments