Fixed potential resource leak

This commit is contained in:
Erik C. Thauvin 2023-01-31 22:09:11 -08:00
parent eefd4ee615
commit 2c271d9116

View file

@ -99,7 +99,7 @@ open class CryptoPrice(val base: String, val currency: String, val amount: BigDe
}.build()
val request = Request.Builder().url(httpUrl).build()
val response = client.newCall(request).execute()
client.newCall(request).execute().use { response ->
val body = response.body?.string() ?: throw CryptoException(
response.code,
id = "empty_response",
@ -120,6 +120,7 @@ open class CryptoPrice(val base: String, val currency: String, val amount: BigDe
throw CryptoException(response.code, id = "parse_error", "Could not parse data.", e)
}
}
}
/**
* Retrieves the buy price.