Skip to content

Commit f5058e7

Browse files
authored
Merge pull request #60 from androidx/rn/no-ntwk
Log a more helpful message when network is not accessible.
2 parents 9c8a37c + cbe4845 commit f5058e7

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2024 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package androidx.build.gradle.core
19+
20+
import okhttp3.Interceptor
21+
import okhttp3.Response
22+
import org.gradle.api.GradleException
23+
import java.io.IOException
24+
25+
class NetworkErrorInterceptor : Interceptor{
26+
override fun intercept(chain: Interceptor.Chain): Response {
27+
val request = chain.request()
28+
return try {
29+
chain.proceed(request)
30+
} catch (ex: IOException) {
31+
throw GradleException("There seems to be some issue with the network access. " +
32+
"Please check your internet access or use --offline with your gradle commands to continue working" +
33+
" without accessing network resources.")
34+
}
35+
}
36+
}

core/src/main/kotlin/androidx/build/gradle/core/TokenInfo.kt

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package androidx.build.gradle.core
1919

2020
import com.google.gson.Gson
2121
import com.google.gson.GsonBuilder
22+
import okhttp3.OkHttpClient
2223
import retrofit2.Call
2324
import retrofit2.Retrofit
2425
import retrofit2.converter.gson.GsonConverterFactory
@@ -37,9 +38,15 @@ interface TokenInfoService {
3738

3839
companion object {
3940
fun tokenService(): TokenInfoService {
41+
val httpClient = OkHttpClient
42+
.Builder()
43+
.addInterceptor(NetworkErrorInterceptor())
44+
.build()
45+
4046
val retrofit = Retrofit.Builder()
4147
.baseUrl("https://www.googleapis.com")
4248
.addConverterFactory(GsonConverterFactory.create(gson()))
49+
.client(httpClient)
4350
.build()
4451

4552
return retrofit.create()

gcpbuildcache/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ gradlePlugin {
5858
}
5959

6060
group = "androidx.build.gradle.gcpbuildcache"
61-
version = "1.0.0-beta09"
61+
version = "1.0.0-beta10"
6262

6363
testing {
6464
suites {

0 commit comments

Comments
 (0)