title: Kotlin coroutines handle error and implementation
body: <p>Using coroutines for the first time. Need help.</p>
  
  <p>Here is my flow:</p>
  
  <p>Presenter wants to login so calls Repository Interface. Repository implements RepositoryInterface.
  So Repository calls APIInterface. APIInterface is implemented by APIInterfaceImpl. 
  The APIInterfaceImpl finally calls the MyRetrofitInterface.</p>
  
  <p>Here is the flow diagrammatically: </p>
  
  <p>Presenter -> Repository -> APIInterfaceImpl -> MyRetrofitInterface</p>
  
  <p>Once I get login response:</p>
  
  <p>APIInterfaceImpl -> Repository -> Stores the data in cache -> Gives http status code to Presenter</p>
  
  <p>Here is my code:</p>
  
  <p>RepositoryInterface.kt</p>
  
  <pre><code>fun onUserLogin(loginRequest: LoginRequest): LoginResponse
  </code></pre>
  
  <p>Repository.kt</p>
  
  <pre><code>class Repository : RepositoryInterface {
     private var apiInterface: APIInterface? = null
  
     override fun onUserLogin(loginRequest: LoginRequest): LoginResponse {
           return apiInterface?.makeLoginCall(loginRequest)
     }
  }
  </code></pre>
  
  <p>APIInterface.kt</p>
  
  <pre><code>suspend fun makeLoginCall(loginRequest): LoginResponse?
  </code></pre>
  
  <p>APIInterfaceImpl.kt</p>
  
  <pre><code>override suspend fun makeLoginCall(loginRequest: LoginRequest): LoginResponse? {
          if (isInternetPresent(context)) {
              try {
                  val response = MyRetrofitInterface?.loginRequest(loginRequest)?.await()
                  return response
              } catch (e: Exception) {
                  //How do i return a status code here
              }
          } else {
          //How do i return no internet here
              return Exception(Constants.NO_INTERNET)
          }
  }
  </code></pre>
  
  <p>MyRetrofitInterface.kt</p>
  
  <pre><code>@POST("login/....")
  fun loginRequest(@Body loginRequest: LoginRequest): Deferred&lt;LoginResponse&gt;?
  </code></pre>
  
  <p>My questions are:</p>
  
  <ol>
  <li>Is my approach architecturally right? </li>
  <li>How do I pass http error codes or no internet connection in my code</li>
  <li>Any more nicer approach to my solution?</li>
  </ol>