-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[#287] ๊ทธ๋ฃน์์ด ๋ค ์ฐฌ ๋ฐฉ์ ๋ค์ด๊ฐ์ ๋, ๋ค ์ฐผ๋ค๊ณ ์๋ฌ ๋ช ์
- Loading branch information
Showing
8 changed files
with
98 additions
and
10 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
data/src/main/java/com/mashup/gabbangzip/sharedalbum/data/base/PicApiErrorParser.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,40 @@ | ||
package com.mashup.gabbangzip.sharedalbum.data.base | ||
|
||
import com.squareup.moshi.Moshi | ||
import com.squareup.moshi.Types | ||
import okhttp3.ResponseBody | ||
import retrofit2.HttpException | ||
|
||
object PicApiErrorParser { | ||
private val moshi = Moshi.Builder().build() | ||
|
||
// PicResponse์ ํ์ ์ ๋์ ์ผ๋ก ์ฒ๋ฆฌํ๊ธฐ ์ํด ParameterizedType ์์ฑ | ||
private val type = Types.newParameterizedType(PicResponse::class.java, Any::class.java) | ||
private val adapter = moshi.adapter<PicResponse<Any>>(type) | ||
|
||
fun parse(e: Throwable): Throwable { | ||
return when (e) { | ||
is HttpException -> { | ||
val error = e.response() | ||
?.errorBody() | ||
?.let { parseErrorResponse(it) } | ||
PicApiException(error) | ||
} | ||
|
||
else -> e | ||
} | ||
} | ||
|
||
private fun parseErrorResponse(errorResponseBody: ResponseBody): PicErrorResponse? { | ||
return try { | ||
val response = adapter.fromJson(errorResponseBody.string()) | ||
if (response != null && !response.isSuccess) { | ||
response.errorResponse | ||
} else { | ||
null | ||
} | ||
} catch (e: Exception) { | ||
null | ||
} | ||
} | ||
} |
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
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
3 changes: 3 additions & 0 deletions
3
...ava/com/mashup/gabbangzip/sharedalbum/presentation/ui/invitation/InvitationCodeUiState.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,6 +1,9 @@ | ||
package com.mashup.gabbangzip.sharedalbum.presentation.ui.invitation | ||
|
||
import androidx.annotation.StringRes | ||
|
||
data class InvitationCodeUiState( | ||
val isLoading: Boolean = false, | ||
val isInvitationSuccessful: Boolean? = null, | ||
@StringRes val errorMessageRes: Int? = null, | ||
) |
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