Skip to content

Commit

Permalink
Log a more helpful message when network is not accessible.
Browse files Browse the repository at this point in the history
  • Loading branch information
rnakade committed Jul 9, 2024
1 parent 9c8a37c commit 5de1dae
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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.")
}
}
}
7 changes: 7 additions & 0 deletions core/src/main/kotlin/androidx/build/gradle/core/TokenInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion gcpbuildcache/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ gradlePlugin {
}

group = "androidx.build.gradle.gcpbuildcache"
version = "1.0.0-beta09"
version = "1.0.0-beta10"

testing {
suites {
Expand Down

0 comments on commit 5de1dae

Please sign in to comment.