diff --git a/app/src/main/java/net/vonforst/evmap/storage/ChargeCardDao.kt b/app/src/main/java/net/vonforst/evmap/storage/ChargeCardDao.kt index 269416a9..9afd52e3 100644 --- a/app/src/main/java/net/vonforst/evmap/storage/ChargeCardDao.kt +++ b/app/src/main/java/net/vonforst/evmap/storage/ChargeCardDao.kt @@ -6,6 +6,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import net.vonforst.evmap.api.goingelectric.ChargeCard import net.vonforst.evmap.api.goingelectric.GoingElectricApi +import java.io.IOException import java.time.Duration import java.time.Instant @@ -35,13 +36,19 @@ class ChargeCardRepository( private suspend fun updateChargeCards() { if (Duration.between(prefs.lastChargeCardUpdate, Instant.now()) < Duration.ofDays(1)) return - val response = api.getChargeCards() - if (!response.isSuccessful) return + try { + val response = api.getChargeCards() + if (!response.isSuccessful) return - for (card in response.body()!!.result) { - dao.insert(card) + for (card in response.body()!!.result) { + dao.insert(card) + } + + prefs.lastChargeCardUpdate = Instant.now() + } catch (e: IOException) { + // ignore, and retry next time + e.printStackTrace() + return } - - prefs.lastChargeCardUpdate = Instant.now() } } \ No newline at end of file diff --git a/app/src/main/java/net/vonforst/evmap/storage/NetworkDao.kt b/app/src/main/java/net/vonforst/evmap/storage/NetworkDao.kt index 981c3c3d..aceae272 100644 --- a/app/src/main/java/net/vonforst/evmap/storage/NetworkDao.kt +++ b/app/src/main/java/net/vonforst/evmap/storage/NetworkDao.kt @@ -5,6 +5,7 @@ import androidx.room.* import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import net.vonforst.evmap.api.goingelectric.GoingElectricApi +import java.io.IOException import java.time.Duration import java.time.Instant @@ -37,13 +38,19 @@ class NetworkRepository( private suspend fun updateNetworks() { if (Duration.between(prefs.lastNetworkUpdate, Instant.now()) < Duration.ofDays(1)) return - val response = api.getNetworks() - if (!response.isSuccessful) return + try { + val response = api.getNetworks() + if (!response.isSuccessful) return - for (name in response.body()!!.result) { - dao.insert(Network(name)) + for (name in response.body()!!.result) { + dao.insert(Network(name)) + } + + prefs.lastNetworkUpdate = Instant.now() + } catch (e: IOException) { + // ignore, and retry next time + e.printStackTrace() + return } - - prefs.lastNetworkUpdate = Instant.now() } } \ No newline at end of file diff --git a/app/src/main/java/net/vonforst/evmap/storage/PlugDao.kt b/app/src/main/java/net/vonforst/evmap/storage/PlugDao.kt index e63bbb1f..93548c11 100644 --- a/app/src/main/java/net/vonforst/evmap/storage/PlugDao.kt +++ b/app/src/main/java/net/vonforst/evmap/storage/PlugDao.kt @@ -5,6 +5,7 @@ import androidx.room.* import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import net.vonforst.evmap.api.goingelectric.GoingElectricApi +import java.io.IOException import java.time.Duration import java.time.Instant @@ -37,13 +38,19 @@ class PlugRepository( private suspend fun updatePlugs() { if (Duration.between(prefs.lastPlugUpdate, Instant.now()) < Duration.ofDays(1)) return - val response = api.getPlugs() - if (!response.isSuccessful) return + try { + val response = api.getPlugs() + if (!response.isSuccessful) return - for (name in response.body()!!.result) { - dao.insert(Plug(name)) + for (name in response.body()!!.result) { + dao.insert(Plug(name)) + } + + prefs.lastPlugUpdate = Instant.now() + } catch (e: IOException) { + // ignore, and retry next time + e.printStackTrace() + return } - - prefs.lastPlugUpdate = Instant.now() } } \ No newline at end of file