Skip to content

Commit 6092755

Browse files
Merge pull request #6 from appwrite/dev
feat: sdk updates
2 parents 9802786 + 8c14f26 commit 6092755

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

library/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import org.jetbrains.kotlin.config.KotlinCompilerVersion
2-
32
plugins {
43
id("com.android.library")
54
id("kotlin-android")
@@ -72,6 +71,9 @@ dependencies {
7271
implementation("com.github.franmontiel:PersistentCookieJar:v1.0.1")
7372

7473
testImplementation 'junit:junit:4.+'
74+
testImplementation "androidx.test.ext:junit-ktx:1.1.2"
75+
testImplementation "androidx.test:core-ktx:1.3.0"
76+
testImplementation "org.robolectric:robolectric:4.5.1"
7577
}
7678

7779
apply from: "${rootProject.projectDir}/scripts/publish-module.gradle"

library/src/main/java/io/appwrite/Client.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class Client @JvmOverloads constructor(
7272
"content-type" to "application/json",
7373
"origin" to "appwrite-android://${context.packageName}",
7474
"user-agent" to "${context.packageName}/${appVersion}, ${System.getProperty("http.agent")}",
75-
"x-sdk-version" to "appwrite:kotlin:0.0.0-SNAPSHOT",
75+
"x-sdk-version" to "appwrite:android:0.0.0-SNAPSHOT",
7676
"x-appwrite-response-format" to "0.8.0"
7777
)
7878
config = mutableMapOf()
@@ -106,7 +106,6 @@ class Client @JvmOverloads constructor(
106106
val builder = OkHttpClient()
107107
.newBuilder()
108108
.cookieJar(cookieJar)
109-
.addInterceptor(HttpLoggingInterceptor().apply { setLevel(HttpLoggingInterceptor.Level.BODY) })
110109

111110
if (!selfSigned) {
112111
http = builder.build()
@@ -148,7 +147,7 @@ class Client @JvmOverloads constructor(
148147
return this
149148
}
150149

151-
private fun addHeader(key: String, value: String): Client {
150+
fun addHeader(key: String, value: String): Client {
152151
headers[key] = value
153152
return this
154153
}
@@ -242,13 +241,18 @@ class Client @JvmOverloads constructor(
242241
val bodyString = response.body
243242
?.charStream()
244243
?.buffered()
245-
?.use(BufferedReader::readText)
244+
?.use(BufferedReader::readText) ?: ""
246245

247-
val error = bodyString?.fromJson(Error::class.java)
246+
val contentType: String = response.headers["content-type"] ?: ""
247+
val error = if (contentType.contains("application/json", ignoreCase = true)) {
248+
bodyString.fromJson(Error::class.java)
249+
} else {
250+
Error(bodyString, response.code)
251+
}
248252

249253
it.cancel(AppwriteException(
250-
error?.message,
251-
error?.code,
254+
error.message,
255+
error.code,
252256
bodyString
253257
))
254258
}

0 commit comments

Comments
 (0)