AnnaSkantz
05/10/2023, 4:28 PMkotlinx.coroutines.JobCancellationException: Parent job is Completed
I managed to solve this by using the following code:
fun class MyClass {
private var client = HttpClient()
private val apiUrl = "<url-string>"
@Throws(Exception::class)
suspend fun myFunction(): String = withContext(Dispatchers.Default) {
try {
val response: HttpResponse = client.get(apiUrlOneCall)
if ((200..299).contains(response.status.value)) {
return@withContext response.bodyAsText()
} else {
throw Exception(response.bodyAsText())
}
} catch (e: Exception) {
throw e
}
}
fun closeConnection() {
client.close()
}
}
Anyone who has encountered this issue before and know if this is an okay solution?