Skip to content

Commit aded210

Browse files
committed
calling response.close() after reading body
1 parent 0b21bee commit aded210

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

android/app/src/main/java/com/httpsms/HttpSmsApiService.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) {
4545
if (response.isSuccessful) {
4646
val payload = ResponseMessage.fromJson(response.body!!.string())?.data
4747
if (payload == null) {
48+
response.close()
4849
Timber.e("cannot decode payload [${response.body}]")
4950
return null
5051
}
51-
Timber.w("response code [${response.code}]")
5252
response.close()
5353
return payload
5454
}
@@ -94,8 +94,8 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) {
9494

9595
val response = client.newCall(request).execute()
9696
if (!response.isSuccessful) {
97-
response.close()
9897
Timber.e("error response [${response.body?.string()}] with code [${response.code}] while receiving message [${body}]")
98+
response.close()
9999
return
100100
}
101101

@@ -120,8 +120,8 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) {
120120

121121
val response = client.newCall(request).execute()
122122
if (!response.isSuccessful) {
123-
response.close()
124123
Timber.e("error response [${response.body?.string()}] with code [${response.code}] while sending heartbeat [$body] for owner [$phoneNumber]")
124+
response.close()
125125
return
126126
}
127127

@@ -156,8 +156,8 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) {
156156

157157
val response = client.newCall(request).execute()
158158
if (!response.isSuccessful) {
159+
Timber.e("error response [${response.body?.string()}] with code [${response.code}] while sending [${event}] event [${body}] for message with ID [${messageId}]")
159160
response.close()
160-
Timber.e("error response [${response.body?.string()}] with code [${response.code}] while sending [${event}] event [${body}] for message with ID [${messageId}]")
161161
return
162162
}
163163

@@ -184,8 +184,8 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) {
184184

185185
val response = client.newCall(request).execute()
186186
if (!response.isSuccessful) {
187-
response.close()
188187
Timber.e("error response [${response.body?.string()}] with code [${response.code}] while sending fcm token [${body}]")
188+
response.close()
189189
return null
190190
}
191191

@@ -207,8 +207,8 @@ class HttpSmsApiService(private val apiKey: String, private val baseURL: URI) {
207207
try {
208208
val response = client.newCall(request).execute()
209209
if (!response.isSuccessful) {
210-
response.close()
211210
Timber.e("error response [${response.body?.string()}] with code [${response.code}] while verifying apiKey [$apiKey]")
211+
response.close()
212212
return Pair("Cannot validate the API key. Check if it is correct and try again.", null)
213213
}
214214

0 commit comments

Comments
 (0)