Skip to content

Commit 8c29fbe

Browse files
committed
[BOOK-420] refactor: Move postErrorDialog to DialogEvents
1 parent 90cdc8b commit 8c29fbe

File tree

4 files changed

+54
-53
lines changed

4 files changed

+54
-53
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.ninecraft.booket.core.common.event
2+
3+
import com.ninecraft.booket.core.common.constants.DialogSpec
4+
import com.ninecraft.booket.core.common.constants.ErrorScope
5+
import com.ninecraft.booket.core.common.utils.isNetworkError
6+
import retrofit2.HttpException
7+
8+
fun postErrorDialog(
9+
errorScope: ErrorScope,
10+
exception: Throwable,
11+
confirmLabel: String = "확인",
12+
onConfirm: () -> Unit = {},
13+
) {
14+
val (title, message) = when {
15+
exception.isNetworkError() -> {
16+
null to "네트워크 연결이 불안정합니다.\n인터넷 연결을 확인해주세요"
17+
}
18+
19+
exception is HttpException -> {
20+
when (errorScope) {
21+
ErrorScope.GLOBAL -> {
22+
null to "알 수 없는 문제가 발생했어요.\n다시 시도해주세요"
23+
}
24+
25+
ErrorScope.LOGIN -> {
26+
"로그인 오류" to "예기치 않은 오류가 발생했습니다.\n다시 로그인 해주세요."
27+
}
28+
29+
ErrorScope.AUTH_SESSION_EXPIRED -> {
30+
null to "세션이 만료되었어요.\n다시 로그인 해주세요"
31+
}
32+
}
33+
}
34+
35+
else -> {
36+
null to "알 수 없는 문제가 발생했어요.\n다시 시도해주세요"
37+
}
38+
}
39+
40+
val spec = DialogSpec(
41+
title = title,
42+
message = message,
43+
confirmLabel = confirmLabel,
44+
onConfirm = onConfirm,
45+
)
46+
47+
EventHelper.sendEvent(event = ReedEvent.ShowDialog(spec))
48+
}

core/common/src/main/kotlin/com/ninecraft/booket/core/common/utils/HandleException.kt

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package com.ninecraft.booket.core.common.utils
22

3-
import androidx.annotation.StringRes
4-
import com.ninecraft.booket.core.common.R
5-
import com.ninecraft.booket.core.common.constants.ErrorDialogSpec
63
import com.ninecraft.booket.core.common.constants.ErrorScope
7-
import com.ninecraft.booket.core.common.event.ErrorEvent
8-
import com.ninecraft.booket.core.common.event.ErrorEventHelper
4+
import com.ninecraft.booket.core.common.event.postErrorDialog
95
import com.ninecraft.booket.core.network.response.ErrorResponse
106
import com.orhanobut.logger.Logger
117
import kotlinx.serialization.SerializationException
@@ -26,7 +22,7 @@ fun handleException(
2622
postErrorDialog(
2723
errorScope = ErrorScope.AUTH_SESSION_EXPIRED,
2824
exception = exception,
29-
action = {
25+
onConfirm = {
3026
onLoginRequired()
3127
},
3228
)
@@ -51,48 +47,6 @@ fun handleException(
5147
}
5248
}
5349

54-
fun postErrorDialog(
55-
errorScope: ErrorScope,
56-
exception: Throwable,
57-
@StringRes buttonLabelResId: Int = R.string.confirm,
58-
action: () -> Unit = {},
59-
) {
60-
val (title, message) = when {
61-
exception.isNetworkError() -> {
62-
null to "네트워크 연결이 불안정합니다.\n인터넷 연결을 확인해주세요"
63-
}
64-
65-
exception is HttpException -> {
66-
when (errorScope) {
67-
ErrorScope.GLOBAL -> {
68-
null to "알 수 없는 문제가 발생했어요.\n다시 시도해주세요"
69-
}
70-
71-
ErrorScope.LOGIN -> {
72-
"로그인 오류" to "예기치 않은 오류가 발생했습니다.\n다시 로그인 해주세요."
73-
}
74-
75-
ErrorScope.AUTH_SESSION_EXPIRED -> {
76-
null to "세션이 만료되었어요.\n다시 로그인 해주세요"
77-
}
78-
}
79-
}
80-
81-
else -> {
82-
null to "알 수 없는 문제가 발생했어요.\n다시 시도해주세요"
83-
}
84-
}
85-
86-
val spec = ErrorDialogSpec(
87-
title = title,
88-
message = message,
89-
buttonLabelResId = buttonLabelResId,
90-
action = action,
91-
)
92-
93-
ErrorEventHelper.sendError(event = ErrorEvent.ShowDialog(spec))
94-
}
95-
9650
private fun HttpException.parseErrorMessage(): String? {
9751
return try {
9852
val errorBody = response()?.errorBody()?.string()

feature/login/src/main/kotlin/com/ninecraft/booket/feature/login/LoginPresenter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import androidx.compose.runtime.rememberCoroutineScope
77
import androidx.compose.runtime.setValue
88
import com.ninecraft.booket.core.common.analytics.AnalyticsHelper
99
import com.ninecraft.booket.core.common.constants.ErrorScope
10-
import com.ninecraft.booket.core.common.utils.postErrorDialog
10+
import com.ninecraft.booket.core.common.event.postErrorDialog
1111
import com.ninecraft.booket.core.data.api.repository.AuthRepository
1212
import com.ninecraft.booket.core.data.api.repository.UserRepository
1313
import com.ninecraft.booket.feature.screens.HomeScreen

feature/splash/src/main/kotlin/com/ninecraft/booket/splash/SplashPresenter.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ import androidx.compose.runtime.rememberCoroutineScope
88
import androidx.compose.runtime.setValue
99
import com.ninecraft.booket.core.common.analytics.AnalyticsHelper
1010
import com.ninecraft.booket.core.common.constants.ErrorScope
11-
import com.ninecraft.booket.core.common.utils.postErrorDialog
11+
import com.ninecraft.booket.core.common.event.postErrorDialog
1212
import com.ninecraft.booket.core.data.api.repository.AuthRepository
1313
import com.ninecraft.booket.core.data.api.repository.RemoteConfigRepository
1414
import com.ninecraft.booket.core.data.api.repository.UserRepository
1515
import com.ninecraft.booket.core.model.AutoLoginState
1616
import com.ninecraft.booket.core.model.OnboardingState
17-
import com.ninecraft.booket.core.ui.R
1817
import com.ninecraft.booket.feature.screens.HomeScreen
1918
import com.ninecraft.booket.feature.screens.LoginScreen
2019
import com.ninecraft.booket.feature.screens.OnboardingScreen
@@ -64,8 +63,8 @@ class SplashPresenter @AssistedInject constructor(
6463
postErrorDialog(
6564
errorScope = ErrorScope.GLOBAL,
6665
exception = exception,
67-
buttonLabelResId = R.string.retry,
68-
action = { checkTermsAgreement() },
66+
confirmLabel = "다시 시도하기",
67+
onConfirm = { checkTermsAgreement() },
6968
)
7069
}
7170
}

0 commit comments

Comments
 (0)