diff --git a/core/src/main/kotlin/androidx/build/gradle/core/NetworkErrorInterceptor.kt b/core/src/main/kotlin/androidx/build/gradle/core/NetworkErrorInterceptor.kt new file mode 100644 index 0000000..d1f78d5 --- /dev/null +++ b/core/src/main/kotlin/androidx/build/gradle/core/NetworkErrorInterceptor.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package androidx.build.gradle.core + +import okhttp3.Interceptor +import okhttp3.Response +import org.gradle.api.GradleException +import java.io.IOException + +class NetworkErrorInterceptor : Interceptor{ + override fun intercept(chain: Interceptor.Chain): Response { + val request = chain.request() + return try { + chain.proceed(request) + } catch (ex: IOException) { + throw GradleException("There seems to be some issue with the network access. " + + "Please use --offline with your gradle commands to continue working " + + "without accessing network resources.") + } + } +} \ No newline at end of file diff --git a/core/src/main/kotlin/androidx/build/gradle/core/TokenInfo.kt b/core/src/main/kotlin/androidx/build/gradle/core/TokenInfo.kt index 2b3f806..3bd3799 100644 --- a/core/src/main/kotlin/androidx/build/gradle/core/TokenInfo.kt +++ b/core/src/main/kotlin/androidx/build/gradle/core/TokenInfo.kt @@ -19,6 +19,7 @@ package androidx.build.gradle.core import com.google.gson.Gson import com.google.gson.GsonBuilder +import okhttp3.OkHttpClient import retrofit2.Call import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory @@ -37,9 +38,15 @@ interface TokenInfoService { companion object { fun tokenService(): TokenInfoService { + val httpClient = OkHttpClient + .Builder() + .addInterceptor(NetworkErrorInterceptor()) + .build() + val retrofit = Retrofit.Builder() .baseUrl("https://www.googleapis.com") .addConverterFactory(GsonConverterFactory.create(gson())) + .client(httpClient) .build() return retrofit.create() diff --git a/gcpbuildcache/build.gradle.kts b/gcpbuildcache/build.gradle.kts index d89a720..5e2a69d 100644 --- a/gcpbuildcache/build.gradle.kts +++ b/gcpbuildcache/build.gradle.kts @@ -58,7 +58,7 @@ gradlePlugin { } group = "androidx.build.gradle.gcpbuildcache" -version = "1.0.0-beta09" +version = "1.0.0-beta10" testing { suites {