Skip to content

Commit

Permalink
Chore : Okhttp3 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
DongChyeon committed Jun 18, 2024
1 parent 5080475 commit 089cbe2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions core/network/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ dependencies {

implementation(libs.retrofit.core)
implementation(libs.retrofit.converter.gson)
implementation(libs.okhttp3.okhttp)
implementation(libs.okhttp3.logging.interceptor)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import store.newsbriefing.app.core.common.BuildConfig
Expand All @@ -29,6 +30,14 @@ object RetrofitModule {
@Singleton
fun provideOkHttpClient(authInterceptor: AuthInterceptor): OkHttpClient {
return OkHttpClient.Builder()
.addNetworkInterceptor(
HttpLoggingInterceptor()
.apply {
if (BuildConfig.DEBUG) {
setLevel(HttpLoggingInterceptor.Level.BODY)
}
}
)
.addInterceptor(authInterceptor)
.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import okhttp3.Response
import store.newsbriefing.app.core.common.util.BriefingLogger
import store.newsbriefing.app.core.datastore.datasource.UserAuthTokenDataSource
import store.newsbriefing.app.core.network.datasource.MemberNetworkDataSource
import java.util.logging.Logger
import javax.inject.Inject

class AuthInterceptor @Inject constructor(
Expand All @@ -35,22 +34,22 @@ class AuthInterceptor @Inject constructor(
}.build()
)

if (response.code() == 200 || response.code() == 201) {
if (response.code == 200 || response.code == 201) {
BriefingLogger.d(
"response code : ${response.code()} ${
"response code : ${response.code} ${
response.peekBody(2048).string()
}"
)
} else {
BriefingLogger.e(
"response code : ${response.code()} ${
"response code : ${response.code} ${
response.peekBody(2048).string()
}"
)
}


if (response.code() == 401 && token != null) {
if (response.code == 401 && token != null) {
val responseBodyString = response.peekBody(2048).string()

val jsonObject = gson.fromJson(responseBodyString, JsonObject::class.java)
Expand Down
6 changes: 5 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ kotlinxCoroutinesAndroid = "1.8.0"
lifecycle-runtime-ktx = "2.8.1"
activity-compose = "1.9.0"
hilt = "2.51"
compose-bom = "2024.05.00"
compose-bom = "2024.04.01"
androidxComposeCompiler = "1.5.7"
androidxHiltNavigationCompose = "1.2.0"
androidxLifecycle = "2.8.1"
ksp = "1.9.21-1.0.16"
androidxAppCompat = "1.7.0"
androidxActivity = "1.9.0"
retrofit = "2.9.0"
okhttp3 = "5.0.0-alpha.11"
material = "1.11.0"
secretsGradlePlugin = "2.0.1"
googleid = "1.1.0"
Expand Down Expand Up @@ -77,6 +78,9 @@ hilt-navigation-compose = { group = "androidx.hilt", name = "hilt-navigation-com
retrofit-core = { group = "com.squareup.retrofit2", name = "retrofit", version.ref = "retrofit" }
retrofit-converter-gson = { group = "com.squareup.retrofit2", name = "converter-gson", version.ref = "retrofit" }

okhttp3-okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp3" }
okhttp3-logging-interceptor = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "okhttp3" }

datastore-preferences = { group = "androidx.datastore", name = "datastore-preferences", version.ref= "datastore" }

javax-inject = { module = "javax.inject:javax.inject", version = "1" }
Expand Down

0 comments on commit 089cbe2

Please sign in to comment.