-
Notifications
You must be signed in to change notification settings - Fork 0
에러 처리 중앙화를 위한 코드를 작성한다 #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,13 @@ | ||
| plugins { | ||
| alias(libs.plugins.metasearch.android.library) | ||
| alias(libs.plugins.metasearch.android.library.compose) | ||
| alias(libs.plugins.metasearch.android.retrofit) | ||
| } | ||
|
|
||
| android { | ||
| namespace = "com.example.metasearch.core.common" | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(projects.core.network) | ||
| } |
6 changes: 6 additions & 0 deletions
6
core/common/src/main/java/com/example/metasearch/core/common/constants/ErrorScope.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.example.metasearch.core.common.constants | ||
|
|
||
| enum class ErrorScope { | ||
| GLOBAL, | ||
| IMAGE_ANALYSIS, | ||
| } |
68 changes: 68 additions & 0 deletions
68
core/common/src/main/java/com/example/metasearch/core/common/utils/EventHandler.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package com.example.metasearch.core.common.utils | ||
|
|
||
| import com.example.metasearch.core.common.constants.ErrorScope | ||
| import kotlinx.coroutines.channels.Channel | ||
| import kotlinx.coroutines.flow.receiveAsFlow | ||
| import retrofit2.HttpException | ||
|
|
||
| object EventHandler { | ||
| private val _eventFlow = Channel<MetaSearchEvent>(Channel.BUFFERED) | ||
| val eventFlow = _eventFlow.receiveAsFlow() | ||
|
|
||
| fun sendEvent(event: MetaSearchEvent) { | ||
| _eventFlow.trySend(event) | ||
| } | ||
| } | ||
|
|
||
| sealed interface MetaSearchEvent { | ||
| data class ShowDialog( | ||
| val dialogSpec: MetaSearchDialogSpec, | ||
| ) : MetaSearchEvent | ||
| } | ||
|
|
||
| data class MetaSearchDialogSpec( | ||
| val title: String? = null, | ||
| val description: String, | ||
| val confirmText: String, | ||
| val dismissText: String? = null, | ||
| val onConfirm: () -> Unit, | ||
| val onDismiss: () -> Unit = {}, | ||
| ) | ||
|
|
||
| fun showErrorDialog( | ||
| errorScope: ErrorScope, | ||
| exception: Throwable, | ||
| confirmText: String = "확인", | ||
| onConfirm: () -> Unit = {}, | ||
| ) { | ||
| val (title, message) = when { | ||
| exception.isNetworkError() -> { | ||
| null to "네트워크 연결이 불안정합니다.\n인터넷 연결을 확인해주세요." | ||
| } | ||
|
|
||
| exception is HttpException -> { | ||
| when (errorScope) { | ||
| ErrorScope.GLOBAL -> { | ||
| null to "알 수 없는 문제가 발생했습니다.\n잠시 후 다시 시도해주세요." | ||
| } | ||
|
|
||
| ErrorScope.IMAGE_ANALYSIS -> { | ||
| null to "이미지 분석 완료 후 다시 시도해주세요." | ||
| } | ||
| } | ||
| } | ||
|
|
||
| else -> { | ||
| null to "알 수 없는 문제가 발생했습니다.\n잠시 후 다시 시도해주세요." | ||
| } | ||
| } | ||
|
|
||
| val spec = MetaSearchDialogSpec( | ||
| title = title, | ||
| description = message, | ||
| confirmText = confirmText, | ||
| onConfirm = onConfirm, | ||
| ) | ||
|
|
||
| EventHandler.sendEvent(event = MetaSearchEvent.ShowDialog(spec)) | ||
| } |
41 changes: 41 additions & 0 deletions
41
core/common/src/main/java/com/example/metasearch/core/common/utils/Exception.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package com.example.metasearch.core.common.utils | ||
|
|
||
| import com.example.metasearch.core.common.constants.ErrorScope | ||
| import retrofit2.HttpException | ||
| import java.io.IOException | ||
| import java.net.ConnectException | ||
| import java.net.SocketTimeoutException | ||
| import java.net.UnknownHostException | ||
|
|
||
| fun handleException( | ||
| exception: Throwable, | ||
| onError: (String) -> Unit, | ||
| ) { | ||
| when { | ||
| exception is HttpException -> { | ||
| when (exception.code()) { | ||
| 401 -> showErrorDialog(ErrorScope.IMAGE_ANALYSIS, exception) | ||
| else -> { | ||
| val message = "서버 오류가 발생했습니다. (${exception.code()})" | ||
| onError(message) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| exception.isNetworkError() -> { | ||
| onError("네트워크 연결이 불안정합니다. 잠시 후 다시 시도해주세요.") | ||
| } | ||
|
|
||
| else -> { | ||
| val message = exception.message ?: "문제가 발생했습니다. 잠시 후 다시 시도해주세요." | ||
| onError(message) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun Throwable.isNetworkError(): Boolean { | ||
| return this is UnknownHostException || | ||
| this is ConnectException || | ||
| this is SocketTimeoutException || | ||
| this is IOException | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,10 +6,16 @@ import androidx.activity.compose.setContent | |
| import androidx.activity.enableEdgeToEdge | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.runtime.LaunchedEffect | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.graphics.Color | ||
| import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen | ||
| import com.example.metasearch.core.common.utils.EventHandler | ||
| import com.example.metasearch.core.common.utils.MetaSearchDialogSpec | ||
| import com.example.metasearch.core.common.utils.MetaSearchEvent | ||
| import com.example.metasearch.core.designsystem.theme.MetaSearchTheme | ||
| import com.example.metasearch.core.ui.component.MetaSearchDialog | ||
| import com.example.metasearch.feature.screens.SplashScreen | ||
| import com.slack.circuit.backstack.rememberSaveableBackStack | ||
| import com.slack.circuit.foundation.Circuit | ||
|
|
@@ -41,9 +47,34 @@ class MainActivity : ComponentActivity() { | |
| } | ||
|
|
||
| MetaSearchTheme { | ||
| val dialogSpec = remember { mutableStateOf<MetaSearchDialogSpec?>(null) } | ||
|
|
||
| val backStack = rememberSaveableBackStack(SplashScreen) | ||
| val navigator = rememberCircuitNavigator(backStack) | ||
|
|
||
| LaunchedEffect(Unit) { | ||
| EventHandler.eventFlow.collect { event -> | ||
| when (event) { | ||
| is MetaSearchEvent.ShowDialog -> dialogSpec.value = event.dialogSpec | ||
| } | ||
| } | ||
| } | ||
|
|
||
| dialogSpec.value?.let { spec -> | ||
| MetaSearchDialog( | ||
| onDismissRequest = { | ||
| dialogSpec.value = null | ||
| }, | ||
| onConfirmRequest = { | ||
| spec.onConfirm() | ||
| dialogSpec.value = null | ||
| }, | ||
| dismissButtonText = spec.dismissText, | ||
| confirmButtonText = spec.confirmText, | ||
| title = spec.title, | ||
| ) | ||
| } | ||
|
Comment on lines
+63
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing dialog description/content. The 🐛 Proposed fix to add content dialogSpec.value?.let { spec ->
MetaSearchDialog(
onDismissRequest = {
dialogSpec.value = null
},
onConfirmRequest = {
spec.onConfirm()
dialogSpec.value = null
},
dismissButtonText = spec.dismissText,
confirmButtonText = spec.confirmText,
title = spec.title,
+ content = { Text(spec.description) },
)
}Note: You'll need to import 🤖 Prompt for AI Agents |
||
|
|
||
| CircuitCompositionLocals(circuit) { | ||
| NavigableCircuitContent( | ||
| modifier = Modifier.fillMaxSize(), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spec.onDismisscallback is not invoked.The
MetaSearchDialogSpecincludes anonDismisscallback, but it's never called when the dialog is dismissed. This could lead to missed cleanup or state updates.🐛 Proposed fix
onDismissRequest = { + spec.onDismiss() dialogSpec.value = null },📝 Committable suggestion
🤖 Prompt for AI Agents