Skip to content

Commit

Permalink
fix: Correct indentation and improve flow handling in getImageOfToday
Browse files Browse the repository at this point in the history
- Fixed suspicious indentation in the try block to ensure logical clarity.
- Explicitly return from `withContext` when the network is unavailable.
- Improved readability and structure of the `getImageOfToday` function.
  • Loading branch information
AliElDerawi committed Jan 5, 2025
1 parent 047e3a6 commit a6b891c
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ class AsteroidRepository(
suspend fun getImageOfToday(): Result<Flow<ImageOfTodayModel>> {
return withContext(ioDispatcher) {
if (!isNetworkConnected()) {
getImageOfTodayFromDataBase()
return@withContext getImageOfTodayFromDataBase()
}

try {
val flow = getImageOfTheDayFlow()
database.imageOfTodayDao.insertImageOfToday(flow.first())
database.imageOfTodayDao.insertImageOfToday(flow.first())
Result.success(flow)
} catch (e: Exception) {
ensureActive()
Expand Down

0 comments on commit a6b891c

Please sign in to comment.