diff --git a/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/network/okhttp/OkHttpApiClient.kt b/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/network/okhttp/OkHttpApiClient.kt index d1b80964d..47f96cdca 100644 --- a/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/network/okhttp/OkHttpApiClient.kt +++ b/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/network/okhttp/OkHttpApiClient.kt @@ -69,15 +69,16 @@ internal class OkHttpApiClient( response: Response, ) { response.use { + val responseBody = response.body?.string().orEmpty() + if (response.isSuccessful) { try { - val typedResponse = gson.fromTypedJson(response.body?.string().orEmpty()) + val typedResponse = gson.fromTypedJson(responseBody) completion(CaptureResult.Success(typedResponse)) } catch (e: Exception) { completion(CaptureResult.Failure(e.toSerializationError())) } } else { - val responseBody = response.body?.string() completion(CaptureResult.Failure(ApiError.ServerError(response.code, responseBody))) } }