Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions android/src/main/kotlin/xyz/juicebox/sdk/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ class Client private constructor (
private fun createNative(configuration: Configuration, previousConfigurations: Array<Configuration>, authTokens: Map<RealmId, AuthToken>?): Long {
val httpSend = Native.HttpSendFn { httpClient, request ->
thread {
val response = Native.HttpResponse()
response.id = request.id
try {
val urlConnection = URL(request.url).openConnection() as HttpsURLConnection

Expand Down Expand Up @@ -166,9 +168,6 @@ class Client private constructor (
urlConnection.outputStream.write(it)
}

val response = Native.HttpResponse()

response.id = request.id
response.statusCode = urlConnection.responseCode.toShort()
response.headers = urlConnection.headerFields.filterKeys { it != null }.map { (key, values) ->
Native.HttpHeader(key, values.joinToString(","))
Expand All @@ -183,9 +182,10 @@ class Client private constructor (
Native.httpClientRequestComplete(httpClient, response)
} catch (t: Throwable) {
Log.e("JuiceboxClient", "Failed to make http call", t)
val fakeErrorResponse = Native.HttpResponse()
fakeErrorResponse.statusCode = -1
Native.httpClientRequestComplete(httpClient, fakeErrorResponse)
response.statusCode = -1
response.body = byteArrayOf()
response.headers = arrayOf()
Native.httpClientRequestComplete(httpClient, response)
}
}
}
Expand Down
Loading