-
Notifications
You must be signed in to change notification settings - Fork 1
네트워크 Exception 처리 방식 변경 #442
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
18 commits
Select commit
Hold shift + click to select a range
6595e1b
Revert "전역적인 network exception 처리 개선 (#432)"
plgafhd 0ffb4d0
Result<T>와 NetworkError 정의
plgafhd 317b9d2
Repository와 Exception -> NetworkError 구현
plgafhd 7698681
ViewModel과 NetworkError -> UiState/UiEvent 구현
plgafhd e0c0906
UI 구현, 디버그 + 리팩토링용 TestScreen 추가
plgafhd 007caa1
Merge branch 'develop' into plgafhd/change-network-exception-handle
plgafhd 528b46a
Delete RootActivityViewModel.kt
plgafhd 3499652
Network -> DomainError로 변경, 하위 계층 분리
plgafhd 70aed26
Exception -> DomainError 변환 함수 통합
plgafhd 7d96add
Result의 확장 함수 onSuccess, onFailure 추가
plgafhd 7cdd84f
Merge branch 'develop' into plgafhd/change-network-exception-handle
plgafhd 539f6fb
빌드 터지는거 수정
plgafhd 37c0019
clearToken의 리턴 타입 Result로 통일
plgafhd 38b1ce2
DisplayMessageResolver 추가
plgafhd dd5c230
DisplayMessageResolver가 모든 displayMessage 결정
plgafhd 8fe94f5
DisplayMessageResolver 인터페이스 분리
plgafhd 045cb52
주석 추가
plgafhd 7116c7c
Merge branch 'develop' into plgafhd/change-network-exception-handle
plgafhd 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
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
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/wafflestudio/snutt2/lib/network/DisplayMessageResolver.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,5 @@ | ||
| package com.wafflestudio.snutt2.lib.network | ||
|
|
||
| interface DisplayMessageResolver { | ||
| fun getDisplayMessage(error: DomainError): String | ||
| } |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/wafflestudio/snutt2/lib/network/DisplayMessageResolverImpl.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,26 @@ | ||
| package com.wafflestudio.snutt2.lib.network | ||
|
|
||
| import android.content.Context | ||
| import com.wafflestudio.snutt2.R | ||
| import dagger.hilt.android.qualifiers.ApplicationContext | ||
| import javax.inject.Inject | ||
|
|
||
| // DisplayMessageResolver는 서버 displayMessage가 없거나, 있는데 클라이언트의 displayMessage와 다른 경우를 커버한다. | ||
| // 추후 테스트를 용이하게 하기 위해 interface 분리되어 있음. | ||
| class DisplayMessageResolverImpl @Inject constructor( | ||
| @ApplicationContext private val context: Context, | ||
| ) : DisplayMessageResolver { | ||
| override fun getDisplayMessage(error: DomainError): String { | ||
| return when (error) { | ||
| is NetworkDisconnect -> context.getString(R.string.error_no_network) | ||
| is ServerFault -> context.getString(R.string.error_server_fault) | ||
| is NoAdminPrivilege -> context.getString(R.string.error_no_admin_privilege) | ||
| is UnknownApp -> context.getString(R.string.error_unknown_app) | ||
| is AuthError.WrongApiKey -> context.getString(R.string.error_wrong_api_key) | ||
| is AuthError.NoUserToken -> context.getString(R.string.error_no_user_token) | ||
| is AuthError.WrongUserToken -> context.getString(R.string.error_wrong_user_token) | ||
| is Unknown -> context.getString(R.string.error_unknown) | ||
| else -> error.displayMessage | ||
| } | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
app/src/main/java/com/wafflestudio/snutt2/lib/network/DomainError.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,30 @@ | ||
| package com.wafflestudio.snutt2.lib.network | ||
|
|
||
| sealed interface DomainError { | ||
| val displayMessage: String | ||
| } | ||
|
|
||
| // 1. Global Errors (모든 API에서 발생 가능) | ||
| // Auth 관련 오류 | ||
| sealed interface AuthError : DomainError { | ||
| data class WrongApiKey(override val displayMessage: String) : AuthError | ||
| data class NoUserToken(override val displayMessage: String) : AuthError // 사실 발생하지 않는 오류일 수 있음. empty token을 보내도 WrongUserToken 발생. | ||
| data class WrongUserToken(override val displayMessage: String) : AuthError | ||
| } | ||
|
|
||
| // 기타 오류 | ||
| data class NetworkDisconnect(override val displayMessage: String) : DomainError | ||
| data class ServerFault(override val displayMessage: String) : DomainError | ||
| data class NoAdminPrivilege(override val displayMessage: String) : DomainError | ||
| data class UnknownApp(override val displayMessage: String) : DomainError | ||
| data class Unknown(override val displayMessage: String) : DomainError | ||
| data class Nothing(override val displayMessage: String) : DomainError | ||
|
|
||
| // 2. Local Errors (특정 API에서만 발생) | ||
| // 회원가입 API | ||
| sealed interface SignupError : DomainError { | ||
| data class InvalidId(override val displayMessage: String) : SignupError | ||
| data class InvalidPassword(override val displayMessage: String) : SignupError | ||
| data class DuplicateId(override val displayMessage: String) : SignupError | ||
| data class UsedEmail(override val displayMessage: String) : SignupError | ||
| } | ||
30 changes: 30 additions & 0 deletions
30
app/src/main/java/com/wafflestudio/snutt2/lib/network/ExceptionMapper.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,30 @@ | ||
| package com.wafflestudio.snutt2.lib.network | ||
|
|
||
| import com.wafflestudio.snutt2.lib.network.call_adapter.ErrorParsedHttpException | ||
| import kotlinx.coroutines.CancellationException | ||
| import okio.IOException | ||
|
|
||
| fun Exception.toDomainError(): DomainError { | ||
| return when (this) { | ||
| is IOException -> NetworkDisconnect("") | ||
JuTaK97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| is CancellationException -> Nothing("") | ||
| is ErrorParsedHttpException -> { | ||
| val displayMessage = this.errorDTO?.displayMessage ?: "" | ||
| return when (this.errorDTO?.code) { | ||
| ErrorCode.SERVER_FAULT -> ServerFault(displayMessage) | ||
| ErrorCode.NO_ADMIN_PRIVILEGE -> NoAdminPrivilege(displayMessage) | ||
| ErrorCode.UNKNOWN_APP -> UnknownApp(displayMessage) | ||
| ErrorCode.WRONG_API_KEY -> AuthError.WrongApiKey(displayMessage) | ||
| ErrorCode.NO_USER_TOKEN -> AuthError.NoUserToken(displayMessage) | ||
| ErrorCode.WRONG_USER_TOKEN -> AuthError.WrongUserToken(displayMessage) | ||
|
|
||
| ErrorCode.INVALID_ID -> SignupError.InvalidId(displayMessage) | ||
| ErrorCode.INVALID_PASSWORD -> SignupError.InvalidPassword(displayMessage) | ||
| ErrorCode.DUPLICATE_ID -> SignupError.DuplicateId(displayMessage) | ||
| ErrorCode.USED_EMAIL -> SignupError.UsedEmail(displayMessage) | ||
| else -> Unknown(displayMessage) | ||
JuTaK97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| else -> Unknown("") | ||
| } | ||
| } | ||
30 changes: 0 additions & 30 deletions
30
app/src/main/java/com/wafflestudio/snutt2/lib/network/GlobalNetworkEventHandler.kt
This file was deleted.
Oops, something went wrong.
62 changes: 0 additions & 62 deletions
62
app/src/main/java/com/wafflestudio/snutt2/lib/network/GlobalNetworkExceptionInterceptor.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.