Skip to content

Instantly share code, notes, and snippets.

@mataku
Last active April 28, 2019 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mataku/8eb195131941bd138b4bda7b4ed861fe to your computer and use it in GitHub Desktop.
Save mataku/8eb195131941bd138b4bda7b4ed861fe to your computer and use it in GitHub Desktop.
import retrofit2.Response
class ApiErrorHandler(val context: Context?) {
fun handle(response: Response) {
// レスポンスコードとエラーレスポンスの中身をパースしてユーザにエラー内容を伝えるためのなにかをする
}
}
import retrofit2.Response
class ExampleActivity : AppCompatActivity(), ExampleView {
fun showError(response: Response) {
ApiErrorHandler(this).handle(response)
}
}
import retrofit2.Response
class ExamplePresenter(val view: ExampleView) {
fun fetchName() {
ApiClient().create(UsersService::class.java)
.fetchName()
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ response ->
if (response.isSuccessful) {
view.showName(response.name)
} else {
view.showError(response)
}
...
}
}
import retrofit2.Response
interface ExampleView {
fun showName(name: String)
fun showError(response: Response)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment