From 22201cffdc84e78fd36230f06a8d2632f2007cc4 Mon Sep 17 00:00:00 2001 From: PranshulGG Date: Sun, 24 May 2026 12:47:17 +0530 Subject: [PATCH] uncomment error handling and cache fallback in MetNorwayRepository and update DateTimeExtensions imports in MetNorwayJsonMapper --- .../weather/metnorway/MetNorwayRepository.kt | 47 ++++++++++--------- .../sources/metnorway/MetNorwayJsonMapper.kt | 4 +- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/com/pranshulgg/weather_master_app/core/network/sources/weather/metnorway/MetNorwayRepository.kt b/app/src/main/java/com/pranshulgg/weather_master_app/core/network/sources/weather/metnorway/MetNorwayRepository.kt index cac151463..994f1ef03 100644 --- a/app/src/main/java/com/pranshulgg/weather_master_app/core/network/sources/weather/metnorway/MetNorwayRepository.kt +++ b/app/src/main/java/com/pranshulgg/weather_master_app/core/network/sources/weather/metnorway/MetNorwayRepository.kt @@ -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 + ) + + } } } diff --git a/app/src/main/java/com/pranshulgg/weather_master_app/data/local/mapper/weather/sources/metnorway/MetNorwayJsonMapper.kt b/app/src/main/java/com/pranshulgg/weather_master_app/data/local/mapper/weather/sources/metnorway/MetNorwayJsonMapper.kt index d5c7fd87d..bee0717e1 100644 --- a/app/src/main/java/com/pranshulgg/weather_master_app/data/local/mapper/weather/sources/metnorway/MetNorwayJsonMapper.kt +++ b/app/src/main/java/com/pranshulgg/weather_master_app/data/local/mapper/weather/sources/metnorway/MetNorwayJsonMapper.kt @@ -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