In my android app I am using a suspendCoroutine to wrap volley's (android's HTTP library) callbacks in a Kotlin coroutine.
Here is my function
private suspend fun requestManger(
url: String,
method: Int,
body: JSONObject?) = suspendCoroutine<Int> { continuation ->
val queue = Volley.newRequestQueue(applicationContext)
val request = object : JsonObjectRequest(method, url, body,
Response.Listener { response ->
Log.d(TAG, "doWork: $response")
continuation.resume(1)
},
Response.ErrorListener { error ->
Log.e(TAG, "doWork: error is", error)
continuation.resume(0)
}) {
override fun getHeaders(): MutableMap<String, String> {
val params = HashMap<String, String>()
params["Content-Type"] = "application/json"
params["Authorization"] = "$idToken"
return params
}
}
queue.add(request)
}
But When I try to build it, It gives me this error
e: java.lang.IllegalStateException: Backend Internal error: Exception during file facade code generation
It this worth noting that this error only appear when i use the continuation object inside the Response.ErrorListener(I get this error even if I type continuation without calling any methods e.g: resume, resumeWithException, etc ) If I don't use it the error disappear but i don't want my function to suspended forever when there is an error