Skip to content

Commit 83194bb

Browse files
committed
GET /restaurants 에 에러핸들러 적용
1 parent 53f5b9b commit 83194bb

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

app/src/main/java/com/wafflestudio/siksha2/network/SikshaApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface SikshaApi {
3434
): NetworkResult<FetchReviewsResult>
3535

3636
@GET("/restaurants/")
37-
suspend fun fetchRestaurants(): FetchRestaurantsResult
37+
suspend fun fetchRestaurants(): NetworkResult<FetchRestaurantsResult>
3838

3939
@POST("/reviews/")
4040
suspend fun leaveMenuReview(@Body req: LeaveReviewParam): LeaveReviewResult

app/src/main/java/com/wafflestudio/siksha2/repositories/MenuRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class MenuRepository @Inject constructor(
4242
dailyMenusDao.insertDailyMenus(payload)
4343
}
4444
else -> {
45-
// TODO: 캐싱 실패 시 별도 로직 필요한가?
45+
throw RuntimeException("")
4646
}
4747
}
4848
}

app/src/main/java/com/wafflestudio/siksha2/repositories/RestaurantRepository.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package com.wafflestudio.siksha2.repositories
33
import com.wafflestudio.siksha2.db.RestaurantsDao
44
import com.wafflestudio.siksha2.models.RestaurantInfo
55
import com.wafflestudio.siksha2.network.SikshaApi
6+
import com.wafflestudio.siksha2.network.result.NetworkResult
67
import com.wafflestudio.siksha2.preferences.SikshaPrefObjects
78
import kotlinx.coroutines.Dispatchers
89
import kotlinx.coroutines.flow.Flow
910
import kotlinx.coroutines.withContext
11+
import java.io.IOException
1012
import javax.inject.Inject
1113
import javax.inject.Singleton
1214

@@ -22,8 +24,15 @@ class RestaurantRepository @Inject constructor(
2224

2325
suspend fun syncWithServer() {
2426
withContext(Dispatchers.IO) {
25-
val data = sikshaApi.fetchRestaurants()
26-
restaurantsDao.update(data.result)
27+
when (val response = sikshaApi.fetchRestaurants()) {
28+
is NetworkResult.Success -> {
29+
val data = response.body
30+
restaurantsDao.update(data.result)
31+
}
32+
else -> {
33+
throw IOException("")
34+
}
35+
}
2736
}
2837
}
2938

0 commit comments

Comments
 (0)