-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ResultCallAdapter 추가하여 에러 파싱 * 시험 적용 * package 변경 * 축제 기능 추가 (#115) * 레이아웃에 토글버튼 추가 * 뷰모델에 플래그와 토글함수 추가 * 뷰모델 플래그와 뷰 연결 * 메뉴 필터링 * 날짜에 따른 필터링 여부 조정 * lint * 토글버튼 디자인 변경 반영 * 날짜 수정 * 홍보 배너 추가 (내용물과 링크는 임시) * 홍보 배너 완성 * 날짜 플래그 최종 수정 * vm.showFestival에 observe 부착 * Revert "축제 기능 추가 (#115)" This reverts commit 194d4de. * fix typo * 에러메시지 기본값 추가 * NetworkResult.map() 추가 * GET /community/posts/{post_id}에 에러핸들러 적용 * NetworkResult에 분기용 메서드 추가 * GET /community/boards/{board_id}에 에러핸들러 적용 * 임시커밋 * GET /community/posts에 에러핸들러 적용 * GET /menus/lo 에 에러핸들러 적용 * 의문의 쓰레기값 수정 * GET /reviews/ 에 에러핸들러 적용 * GET /reviews/filter 에 에러핸들러 적용 * GET /restaurants 에 에러핸들러 적용 * ErrorDto 수정 (detail -> message) * GET /reviews, /reviews/images 에 에러핸들러 적용 * POST /auth/login 에 에러핸들러 적용 * POST /auth/refresh 에 에러핸들러 적용 * GET /reviews/comments/recommendation 에 에러핸들러 적용 * GET /reviews/dist 에 에러핸들러 적용 * POST /voc 에 에러핸들러 적용 * GET /auth/me/image 에 에러핸들러 적용 * PATCH /auth/me/image/profile, GET /auth/nicknames/validate 에 에러핸들러 적용 * GET /versions/android 에 에러핸들러 적용 * POST /menus/{menu_id}/like, /menus/{menu_id}/unlike 에 에러핸들러 적용 * GET /community/boards 에 에러핸들러 적용 * GET /community/posts/me 에 에러핸들러 적용 * POST /community/comments 에 에러핸들러 적용 * POST /community/posts/{post_id}/like, /community/posts/{post_id}/unlike 에 에러핸들러 적용 * POST, PATCH /community/posts 에 에러핸들러 적용 * POST /community/comments/{comment_id}/like, /community/comments/{comment_id}/unlike 에 에러핸들러 적용 * POST /community/posts/{post_id}/report, /community/comments/{comment_id}/report 에 에러핸들러 적용 * GET /community/posts/popular/trending 에 에러핸들러 적용 --------- Co-authored-by: eastshine2741 <[email protected]>
- Loading branch information
1 parent
f8962e5
commit c696f8b
Showing
33 changed files
with
753 additions
and
458 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
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
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/wafflestudio/siksha2/network/dto/core/ErrorDto.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,24 @@ | ||
package com.wafflestudio.siksha2.network.dto.core | ||
|
||
import com.squareup.moshi.JsonClass | ||
|
||
// TODO: error dto 형식 서버와 확정 | ||
/*@JsonClass(generateAdapter = true) | ||
data class ErrorDto( | ||
@Json(name = "detail") val details: List<ErrorDetail>, | ||
val body: String?, | ||
val message: String, | ||
) | ||
data class ErrorDetail( | ||
val type: String, | ||
val location: List<String>, | ||
val msg: String, | ||
val input: String?, | ||
val url: String, | ||
)*/ | ||
|
||
@JsonClass(generateAdapter = true) | ||
data class ErrorDto( | ||
val message: String? | ||
) |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/wafflestudio/siksha2/network/result/NetworkResult.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,41 @@ | ||
package com.wafflestudio.siksha2.network.result | ||
|
||
import java.io.IOException | ||
|
||
sealed interface NetworkResult<out T : Any> { | ||
data class Success<T : Any>(val body: T) : NetworkResult<T> | ||
data class Failure(val message: String) : NetworkResult<Nothing> | ||
data class NetworkError(val exception: IOException) : NetworkResult<Nothing> | ||
data class UnknownError(val t: Throwable?) : NetworkResult<Nothing> | ||
|
||
fun <R : Any> map(transform: (T) -> R): NetworkResult<R> = when (this) { | ||
is Success -> Success(transform(body)) | ||
is Failure -> this | ||
is NetworkError -> this | ||
is UnknownError -> this | ||
} | ||
|
||
fun onSuccess(action: (value: T) -> Unit): NetworkResult<T> = apply { | ||
if (this is Success) action(body) | ||
} | ||
|
||
fun onFailure(action: (message: String) -> Unit): NetworkResult<T> = apply { | ||
if (this is Failure) action(message) | ||
} | ||
|
||
fun onNetworkError(action: (exception: IOException) -> Unit): NetworkResult<T> = apply { | ||
if (this is NetworkError) action(exception) | ||
} | ||
|
||
fun onUnknownError(action: (exception: Throwable?) -> Unit): NetworkResult<T> = apply { | ||
if (this is UnknownError) action(t) | ||
} | ||
|
||
fun onError(action: (t: Throwable?) -> Unit): NetworkResult<T> = apply { | ||
when (this) { | ||
is NetworkError -> action(exception) | ||
is UnknownError -> action(t) | ||
else -> Unit | ||
} | ||
} | ||
} |
Oops, something went wrong.