title: Access variable inside interceptor
body: <p><strong>Context:</strong></p>
  <p>I have an interceptor, I receive a URL as a parameter, if that URL doesn't work, inside the interceptor, in the variable &quot;endpointToExecute&quot; I assign a second URL. So, when I create my Retrofit, I should assign the &quot;endpointToExecute&quot; variable in &quot;baseUrl&quot;.</p>
  <p><strong>Problem:</strong></p>
  <p>The problem is that it always assigns the first url, I can never access the second URL, if &quot;https://aaaa.com/&quot; fails. The question would be, how do I access the value of my variable &quot;endpointToExecute&quot; that is inside an interceptor?</p>
  <p><strong>Code:</strong></p>
  <pre><code>fun getRetrofit(url:&quot;https://aaaa.com/&quot;): Retrofit {
  
          if(url == &quot;https://aaaa.com/&quot;){
              var endpointToExecute = url
              val clientBuilder = OkHttpClient.Builder()
              clientBuilder.addInterceptor { chain -&gt;
                  val request = chain.request()
                  val response = chain.proceed(request)
                  if (!response.isSuccessful) {
                      endpointToExecute = &quot;https://bbbb.com/&quot;
                  }
                  response
              }
  
              return Retrofit.Builder()
                  .baseUrl(endpointToExecute)
                  .addConverterFactory(GsonConverterFactory.create(AppServiceGenerator.gson))
                  .addCallAdapterFactory(
                      RxErrorHandlingCallAdapterFactory.createWithScheduler(Schedulers.io()))
                  .client(clientBuilder.build()) 
                  .build()
  
          }
  
      }
  </code></pre>