mirror of
https://github.com/PranshulGG/WeatherMaster.git
synced 2026-10-23 11:33:42 -05:00
uncomment error handling and cache fallback in MetNorwayRepository and update DateTimeExtensions imports in MetNorwayJsonMapper
This commit is contained in:
1 parent
ee91e8f8d2
commit
22201cffdc
2 files changed
+26
-25
No files matched your search
+24
-23
@@ -3,6 +3,7 @@ package com.pranshulgg.weather_master_app.core.network.sources.weather.metnorway
|
||||
import com.pranshulgg.weather_master_app.core.model.domain.location.Location
|
||||
import com.pranshulgg.weather_master_app.core.model.weather.WeatherResult
|
||||
import com.pranshulgg.weather_master_app.core.model.weather.WeatherResultType
|
||||
import com.pranshulgg.weather_master_app.core.utils.weather.cache.isWeatherCacheSafe
|
||||
import com.pranshulgg.weather_master_app.core.utils.weather.cache.shouldReturnWeatherCache
|
||||
import com.pranshulgg.weather_master_app.data.local.dao.location.LocationsDao
|
||||
import com.pranshulgg.weather_master_app.data.local.dao.weather.WeatherDao
|
||||
@@ -43,36 +44,36 @@ class MetNorwayRepository @Inject constructor(
|
||||
else -> {}
|
||||
}
|
||||
|
||||
// return@withContext try {
|
||||
return@withContext try {
|
||||
|
||||
|
||||
val response = api.fetchWeather(location.latitude, location.longitude)
|
||||
val response = api.fetchWeather(location.latitude, location.longitude)
|
||||
|
||||
val body =
|
||||
response.body()
|
||||
?: return@withContext WeatherResult.Error(exception = UnknownHostException())
|
||||
val body =
|
||||
response.body()
|
||||
?: return@withContext WeatherResult.Error(exception = UnknownHostException())
|
||||
|
||||
|
||||
val domain = body.toDomain(location)
|
||||
val domain = body.toDomain(location)
|
||||
|
||||
weatherDao.insertWeather(
|
||||
domain.current.toCurrentWeatherEntity(location.id),
|
||||
domain.hourly.toHourlyWeatherEntity(location.id),
|
||||
domain.daily.toDailyWeatherEntity(location.id),
|
||||
location.id
|
||||
)
|
||||
WeatherResult.Success(domain)
|
||||
weatherDao.insertWeather(
|
||||
domain.current.toCurrentWeatherEntity(location.id),
|
||||
domain.hourly.toHourlyWeatherEntity(location.id),
|
||||
domain.daily.toDailyWeatherEntity(location.id),
|
||||
location.id
|
||||
)
|
||||
WeatherResult.Success(domain)
|
||||
|
||||
// } catch (e: Exception) {
|
||||
//
|
||||
// val isCacheSafe = isWeatherCacheSafe(cache)
|
||||
//
|
||||
// WeatherResult.Error(
|
||||
// exception = e,
|
||||
// if (isCacheSafe) cache?.toDomain() else null
|
||||
// )
|
||||
//
|
||||
// }
|
||||
} catch (e: Exception) {
|
||||
|
||||
val isCacheSafe = isWeatherCacheSafe(cache)
|
||||
|
||||
WeatherResult.Error(
|
||||
exception = e,
|
||||
if (isCacheSafe) cache?.toDomain() else null
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -10,8 +10,8 @@ import com.pranshulgg.weather_master_app.core.model.weather.wind.WindDirection
|
||||
import com.pranshulgg.weather_master_app.core.network.sources.weather.metnorway.MetNorwayWeatherConditionMap
|
||||
import com.pranshulgg.weather_master_app.core.network.sources.weather.metnorway.json.MetNorwayForecastJson
|
||||
import com.pranshulgg.weather_master_app.core.network.sources.weather.metnorway.json.MetNorwayForecastTimeSeriesJson
|
||||
import com.pranshulgg.weather_master_app.core.utils.Extensions.iso8601TimestampToMilliseconds
|
||||
import com.pranshulgg.weather_master_app.core.utils.Extensions.normalizeToDay
|
||||
import com.pranshulgg.weather_master_app.core.utils.extensions.DateTimeExtensions.iso8601TimestampToMilliseconds
|
||||
import com.pranshulgg.weather_master_app.core.utils.extensions.DateTimeExtensions.normalizeToDay
|
||||
import com.pranshulgg.weather_master_app.core.utils.weather.astronomy.getMoonTimings
|
||||
import com.pranshulgg.weather_master_app.core.utils.weather.astronomy.getSunTimings
|
||||
import com.pranshulgg.weather_master_app.core.utils.weather.calculations.computeApparentTemperature
|
||||
|
||||
Reference in new issue
Block a user