-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 리뷰 반영 - 레트로핏 버전 변수 정의 - Failure 시 Throwable로 다루도록 변경 - request url 기록 - Exception 구조화
- Loading branch information
Showing
11 changed files
with
106 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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 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
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/moyerun/moyeorun_android/common/exceptions/ApiException.kt
This file contains 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,11 @@ | ||
package com.moyerun.moyeorun_android.common.exceptions | ||
|
||
import com.moyerun.moyeorun_android.network.api.Error | ||
|
||
class ApiException(val url: String, val error: Error) : RuntimeException() { | ||
val case: String | ||
get() = error.case | ||
|
||
override val message: String? | ||
get() = error.message | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/moyerun/moyeorun_android/common/exceptions/NetworkException.kt
This file contains 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,7 @@ | ||
package com.moyerun.moyeorun_android.common.exceptions | ||
|
||
import java.lang.RuntimeException | ||
|
||
class NetworkException(message: String, cause: Throwable) : RuntimeException(message, cause) { | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/moyerun/moyeorun_android/network/api/ApiErrorCase.kt
This file contains 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,22 @@ | ||
package com.moyerun.moyeorun_android.network.api | ||
|
||
import com.moyerun.moyeorun_android.common.exceptions.ApiException | ||
|
||
enum class ApiErrorCase(val case: String) { | ||
// 서버와 합의된 에러 케이스들을 정의합니다. | ||
NOT_LOGIN("100"), // TODO : 예시입니다. 실제 로그인 작업 시 수정해주세요. | ||
UNKNOWN("999"); | ||
|
||
companion object { | ||
private fun findError(case: String): ApiErrorCase { | ||
return values().find { it.case == case } ?: UNKNOWN | ||
} | ||
|
||
fun getException(url: String, error: Error, cause: Throwable? = null): Throwable { | ||
return when(findError(error.case)) { | ||
NOT_LOGIN -> { TODO() } | ||
else -> ApiException(url, error) | ||
} | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
app/src/main/java/com/moyerun/moyeorun_android/network/api/ApiService.kt
This file contains 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
6 changes: 2 additions & 4 deletions
6
app/src/main/java/com/moyerun/moyeorun_android/network/calladapter/ApiResult.kt
This file contains 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,12 +1,10 @@ | ||
package com.moyerun.moyeorun_android.network.callAdapter | ||
|
||
import com.moyerun.moyeorun_android.network.api.Error | ||
package com.moyerun.moyeorun_android.network.calladapter | ||
|
||
/** | ||
* Success : API 호출 성공 시, body를 Wrapping 합니다. | ||
* Failure : API 호출 실패 시, errorBody를 Wrpping 합니다. | ||
*/ | ||
sealed class ApiResult<out T> { | ||
data class Success<T>(val body: T) : ApiResult<T>() | ||
data class Failure(val errorBody: Error) : ApiResult<Nothing>() | ||
data class Failure(val exception: Throwable) : ApiResult<Nothing>() | ||
} |
This file contains 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
2 changes: 1 addition & 1 deletion
2
app/src/main/java/com/moyerun/moyeorun_android/network/calladapter/ApiResultCallAdapter.kt
This file contains 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
2 changes: 1 addition & 1 deletion
2
...main/java/com/moyerun/moyeorun_android/network/calladapter/ApiResultCallAdapterFactory.kt
This file contains 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
2 changes: 1 addition & 1 deletion
2
app/src/main/java/com/moyerun/moyeorun_android/network/client/Retrofit.kt
This file contains 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