-
Notifications
You must be signed in to change notification settings - Fork 0
[Refactor] API 호출 오류 핸들링 개선 #391
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 20 commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
9096ecc
feat: ApiResult 추가
PeraSite a68d0bd
refactor: Repository 시그니처 정리
PeraSite 9e2a51d
feat: RepositoryImpl ApiResult 사용
PeraSite 05159c6
feat: Service ApiResult 사용
PeraSite 1877369
feat: Presentation 레이어 ApiResult 적용
PeraSite a3362fe
feat: ApiResult 처리 CallAdapter 추가
PeraSite c09b185
fix: getFixMenu만 크래시가 발생하던 문제 수정
PeraSite 63f4a0e
refactor: ArrayList를 List로 정리
PeraSite 6cc8dec
chore: BaseResponseConverter 삭제
PeraSite dd60769
fix: 런타임 발생 오류 해결
PeraSite f587b8c
chore: 로그인 실패 줄바꿈 삭제
PeraSite d140199
fix: early return 추가
PeraSite ab61862
refactor: 로그아웃 로직 병합
PeraSite 886200a
chore: List로 타입 통일화
PeraSite 019859d
feat: NetworkError 대응 Activity 추가
PeraSite 8281771
feat: HealthCheck 모듈 추가
PeraSite 7701831
fix: ApiResult의 함수를 외부 확장 함수로 변경
PeraSite d09d4b7
feat: NetworkError 발생 시 ServerErrorActivity 이동 추가
PeraSite b77cbf5
refactor: IntroActivity 함수화
PeraSite 2c91d5c
refactor: HealthCheck use-case가 boolean을 사용하게 수정, autoLogin 로직 리팩토링
PeraSite 7da9ca8
refactor: nested it 이름 변경
PeraSite 6412fd5
fix: /actuator/health 가 BaseResponse 형태를 따르지 않아 발생하던 문제 수정
PeraSite a16114d
docs: ApiResult의 각 data class 주석 추가
PeraSite 31e0c99
docs: ApiResult 매핑 함수 주석 추가
PeraSite e58a3a9
chore: 기존 PartnershipRepositoryImpl 주석 복구
PeraSite f64d784
refactor: ApiResult.map 외부 확장 함수로 분리
PeraSite ae15754
refactor: true 반환 one-liner로 변경
PeraSite b221c36
refactor: getUserNickName ApiResult 매핑 형태 개선
PeraSite 04055fc
refactor: 불필요한 orNull 및 emptyList() 처리 개선
PeraSite cb24faf
refactor: ApiResult가 UI 레이어로 넘어가지 않게 loginWithKakao 수정
PeraSite 855d229
refactor: 미사용 Response 객체 삭제
PeraSite 976744f
refactor: 하드 코딩된 부분을 Restraunt enum 사용하게 수정
PeraSite fb4b49c
refactor: 안쓰는 함수 제거
PeraSite 55cadf0
refactor: 어떤 식당 메뉴 가져올 것인지 한번에 호출하게 변경
PeraSite 1689f2e
refactor: 불필요한 UiState.Success의 nullable 제거
PeraSite f214504
fix: UiState.Success 변경 대응
PeraSite 0ec4086
feat: Health Check 관련 코드 삭제
PeraSite f61979e
feat: NetworkErrorEventBus로 네트워크 오류 발생 시 ServerErrorActivity로 이동
PeraSite 1d40b3c
refactor: Indent 적게 수정
PeraSite d08ea51
refactor: Deprecate된 arguments.getSerializable 개선
PeraSite bc9208d
chore: 불필요한 out 삭제
PeraSite 60ffc27
chore: 불필요한 context 삭제
PeraSite d12a307
fix: Deprecate된 fragmentManager 접근 수정
PeraSite be68944
docs: 누락된 주석 추가
PeraSite 1bdf871
refactor: BaseActivity, IntroActivity에서 공통적으로 NetworkErrorEventBus에 구…
PeraSite 73c652a
Merge branch 'develop' into refactor/error-handling
PeraSite dd79dde
feat: HealthCheck 관련 Service, Repository, UseCase 추가
PeraSite 4503516
feat: IntroViewModel에서 최초 실행 시 health check하게끔 수정
PeraSite 265a86b
refactor: MenuViewModel 클린 아키텍처 적용
PeraSite 3c525bd
chore: 오타 수정
PeraSite f206d82
refactor: MapViewModel runCatching 리팩토링
PeraSite fcb7647
refactor: UserInfoViewModel try-catch 리팩토링
PeraSite 2c86c4f
refactor: MyPageViewModel runCatching 리팩토링
PeraSite 7397c53
refactor: SignOutViewModel try-catch 리팩토링
PeraSite 9ff0cb8
refactor: MainViewModel runCatching 리팩토링
PeraSite 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
Some comments aren't visible on the classic Files Changed page.
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
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/eatssu/android/data/dto/response/HealthCheckResponse.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,9 @@ | ||
| package com.eatssu.android.data.dto.response | ||
|
|
||
| import com.google.gson.annotations.SerializedName | ||
|
|
||
| data class HealthCheckResponse( | ||
| @SerializedName("status") | ||
| val status: String | ||
| ) | ||
|
|
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
46 changes: 46 additions & 0 deletions
46
app/src/main/java/com/eatssu/android/data/model/ApiResult.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,46 @@ | ||
| package com.eatssu.android.data.model | ||
|
|
||
| import java.io.IOException | ||
|
|
||
| sealed interface ApiResult<out T> { | ||
PeraSite marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fun <R : Any> map(transform: (T) -> R): ApiResult<R> = when (this) { | ||
| is Success -> Success(transform(data)) | ||
PeraSite marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| is Failure -> Failure(responseCode, message) | ||
| is NetworkError -> NetworkError(exception) | ||
| is UnknownError -> UnknownError(exception) | ||
| } | ||
|
|
||
| data class Success<T : Any>(val data: T) : ApiResult<T> | ||
PeraSite marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| data class Failure( | ||
PeraSite marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| val responseCode: Int, | ||
| val message: String? | ||
| ) : ApiResult<Nothing> | ||
|
|
||
| data class NetworkError( | ||
PeraSite marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| val exception: IOException | ||
| ) : ApiResult<Nothing> | ||
|
|
||
| data class UnknownError( | ||
PeraSite marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| val exception: Throwable | ||
| ) : ApiResult<Nothing> | ||
|
|
||
| } | ||
|
|
||
| fun <TElement, TList : List<TElement>> ApiResult<TList>.orEmptyList(): List<TElement> = | ||
PeraSite marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| when (this) { | ||
| is ApiResult.Success -> data | ||
| else -> emptyList() | ||
| } | ||
|
|
||
| fun ApiResult<Unit>.isSuccess(): Boolean = this is ApiResult.Success | ||
PeraSite marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| fun <T> ApiResult<T>.orElse(default: T): T = when (this) { | ||
PeraSite marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| is ApiResult.Success -> data | ||
| else -> default | ||
| } | ||
|
|
||
| fun <T> ApiResult<T>.orNull(): T? = when (this) { | ||
PeraSite marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| is ApiResult.Success -> data | ||
| else -> null | ||
| } | ||
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/eatssu/android/data/repository/HealthCheckRepositoryImpl.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,18 @@ | ||
| package com.eatssu.android.data.repository | ||
|
|
||
| import com.eatssu.android.data.model.ApiResult | ||
| import com.eatssu.android.data.service.HealthCheckService | ||
| import com.eatssu.android.domain.repository.HealthCheckRepository | ||
| import javax.inject.Inject | ||
|
|
||
| class HealthCheckRepositoryImpl @Inject constructor( | ||
| private val healthCheckService: HealthCheckService | ||
| ) : HealthCheckRepository { | ||
| override suspend fun checkServerHealth(): Boolean = | ||
| when (val result = healthCheckService.checkHealth()) { | ||
| is ApiResult.NetworkError -> false | ||
PeraSite marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| is ApiResult.Success -> result.data.status == "UP" | ||
| else -> false | ||
| } | ||
| } | ||
|
|
||
33 changes: 7 additions & 26 deletions
33
app/src/main/java/com/eatssu/android/data/repository/MealRepositoryImpl.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 |
|---|---|---|
| @@ -1,43 +1,24 @@ | ||
| package com.eatssu.android.data.repository | ||
|
|
||
| import com.eatssu.android.data.dto.response.BaseResponse | ||
| import com.eatssu.android.data.dto.response.MenuOfMealResponse | ||
| import com.eatssu.android.data.dto.response.MenusInformation | ||
| import com.eatssu.android.data.dto.response.toDomain | ||
| import com.eatssu.android.data.model.orEmptyList | ||
| import com.eatssu.android.data.service.MealService | ||
| import com.eatssu.android.domain.repository.MealRepository | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.flow | ||
| import javax.inject.Inject | ||
|
|
||
| class MealRepositoryImpl @Inject constructor( | ||
| private val mealService: MealService, | ||
| ) : MealRepository { | ||
|
|
||
| override suspend fun getTodayMeal( //todo 분기처리 어떻게 할지? | ||
| override suspend fun getTodayMeal( | ||
| date: String, | ||
| restaurant: String, | ||
| time: String | ||
| ): Flow<List<List<String>>> { | ||
| return flow { | ||
| try { | ||
| val response = mealService.getTodayMeal2(date, restaurant, time) | ||
|
|
||
| // 응답이 성공적이라면 Result.success()로 감싸서 Flow로 반환 | ||
| if (response.isSuccess == true) { | ||
| response.result?.let { emit(it.toDomain()) } // 성공시 데이터를 반환 | ||
| } else { | ||
| // 실패한 경우에는 Result.failure()로 실패 정보 반환 | ||
| emit(emptyList()) | ||
| } | ||
| } catch (e: Exception) { | ||
| // 네트워크 오류 또는 예외가 발생한 경우에는 Result.failure()로 반환 | ||
| // emit(ApiResult.Failure(e)) | ||
| } | ||
| } | ||
| ): List<List<String>> { | ||
| return mealService.getTodayMeal(date, restaurant, time).orEmptyList().toDomain() | ||
PeraSite marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| override suspend fun getMenuInfoByMealId(mealId: Long): Flow<BaseResponse<MenuOfMealResponse>> = | ||
| flow { | ||
| emit(mealService.getMenuInfoByMealId(mealId)) | ||
| } | ||
| override suspend fun getMenuInfoByMealId(mealId: Long): List<MenusInformation> = | ||
| mealService.getMenuInfoByMealId(mealId).map { it.briefMenus }.orEmptyList() | ||
| } | ||
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
10 changes: 3 additions & 7 deletions
10
app/src/main/java/com/eatssu/android/data/repository/ReportRepositoryImpl.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 |
|---|---|---|
| @@ -1,19 +1,15 @@ | ||
| package com.eatssu.android.data.repository | ||
|
|
||
| import com.eatssu.android.data.dto.request.ReportRequest | ||
| import com.eatssu.android.data.dto.response.BaseResponse | ||
| import com.eatssu.android.data.model.isSuccess | ||
| import com.eatssu.android.data.service.ReportService | ||
| import com.eatssu.android.domain.repository.ReportRepository | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.flow | ||
| import javax.inject.Inject | ||
|
|
||
| class ReportRepositoryImpl @Inject constructor(private val reportService: ReportService) : | ||
| ReportRepository { | ||
|
|
||
| override suspend fun reportReview(body: ReportRequest): Flow<BaseResponse<Void>> = | ||
| flow { | ||
| emit(reportService.reportReview(body)) | ||
| } | ||
| override suspend fun reportReview(body: ReportRequest): Boolean = | ||
| reportService.reportReview(body).isSuccess() | ||
|
|
||
| } |
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
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.