Примеры обработчиков запросов

Через классические onResponse/onFailure

 val authApi = ControllerApi().getAuthApi()
 val refreshTokenReq = authApi.register(user)
 
 refreshTokenReq.enqueue(object : Callback<SomeReturnData>) {
     override fun onResponse(...) {
         if (response.isSuccessful) {
             // 2xx, 3xx
         }
         else {
             // 4xx, 5xx
         }
     }
     override fun onFailure(...) {
         // non http, network errors
     }
 }

Или через await

 val authApi = ControllerApi().getAuthApi()
 authApi.register(user).await().let {
     if (response.isSuccessful) {
         ...
     }
 }

Last updated

Was this helpful?