2022年04月21日

https://github.com/ParadiseHell/one/blob/main/src/main/kotlin/org/paradisehell/one/RetrofitProxy.kt

Example

  1. // call `proxyRetrofit` after `Retrofit#create`, in this method it will handle
  2. // exception automatically.
  3. val service = retrofit.create(WanAndroidService::class.java).proxyRetrofit()
  4. // test
  5. service.test()
  6. .onSuccess { println("execute test success ==> $it") }
  7. .onFailure { println("execute test() failure ==> $it") }
  8. // userInfo
  9. .onFailureThen { service.userInfo() }
  10. ?.onSuccess { println("execute userInfo success ==> $it") }
  11. ?.onFailure { println("execute userInfo() failure ==> $it") }
  12. // banner
  13. ?.onFailureThen { service.banner() }
  14. ?.onSuccess { println("execute banner() success ==> $it") }
  15. ?.onFailure { println("execute banner() failure ==> $it") }