Author: Adam Evyčędo <git@apiote.xyz>
catch errors when searching journeys
%!v(PANIC=String method: strings: negative Repeat count)
diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/journeys/JourneysViewModel.kt b/app/src/main/java/xyz/apiote/bimba/czwek/journeys/JourneysViewModel.kt index 961dd33b1e600b758ad71fb0098aeb8925628eb8..8f54abe1ac6a5e29c1d615a22b523201afad8fd2 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/journeys/JourneysViewModel.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/journeys/JourneysViewModel.kt @@ -10,6 +10,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import kotlinx.coroutines.launch +import org.openapitools.client.infrastructure.ServerException import xyz.apiote.bimba.czwek.repo.Journey import xyz.apiote.bimba.czwek.repo.JourneyParams import xyz.apiote.bimba.czwek.repo.Place @@ -20,7 +21,6 @@ private val _journeys = MutableLiveData<List<Journey>>() val journeys: LiveData<List<Journey>> = _journeys - // FIXME when not in foreground, throws java.net.SocketException: Software caused connection abort fun getJourneys(context: Context, origin: Place, destination: Place, params: JourneyParams) { viewModelScope.launch { try { @@ -29,6 +29,12 @@ xyz.apiote.bimba.czwek.api.getJourney(origin, destination, params, context) } catch (e: SocketTimeoutException) { _journeys.value = emptyList<Journey>() Log.e("Journeys", "timeout: $e") + } catch (e: ServerException) { + _journeys.value = emptyList<Journey>() + Log.w("Suggestion", "Transitous returned: ${e.statusCode}, ${e.message}") + } catch (e: Exception) { + _journeys.value = emptyList<Journey>() + Log.w("Suggestion", "Exception: $e") } } }