Ktor Response readText() already received exception
See original GitHub issueKtor Version
1.2.0-alpha-2
Ktor Engine Used(client or server and name)
Client OkHttp
JVM Version, Operating System and Relevant Context
JVM 1.8
Feedback
readText() on a response that failed used to work, but doesn’t anymore. readBytes() still works which makes me think that this is an undesirable behaviour.
If it is the desired behaviour, I’d love the rationale behind it as well as the best way to transform the response body into a String
.
val client = HttpClient(MockEngine { MockHttpResponse(it.call, HttpStatusCode.BadRequest) })
try {
client.get<String>("www.google.com")
} catch (exception: ResponseException) {
// io.ktor.client.call.DoubleReceiveException: Response already received: io.ktor.client.call.HttpClientCall@27ce24aa
exception.response.readText()
// This is fine
String(exception.response.readBytes())
}
Stacktrace
io.ktor.client.call.DoubleReceiveException: Response already received: io.ktor.client.call.HttpClientCall@27ce24aa
at io.ktor.client.call.HttpClientCall.receive(HttpClientCall.kt:57)
at io.ktor.client.response.HttpResponseKt.readText(HttpResponse.kt:80)
at io.ktor.client.response.HttpResponseKt.readText$default(HttpResponse.kt:74)
at suite.TestSuiteMultiCluster$stuff$1.invokeSuspend(TestSuiteMultiCluster.kt:84)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:12 (4 by maintainers)
Top Results From Across the Web
Ktor Response readText() already received exception
This issue was imported from GitHub issue: https://github.com/ktorio/ktor/issues/1038. Ktor Version. 1.2.0-alpha-2. Ktor Engine Used(client or server and ...
Read more >readText
Read the HttpResponse.content as a String. You can pass an optional charset to specify a charset in the case no one is specified...
Read more >Parsing an error body in a ktor HTTPClient - kotlin
My query here is I am not able to access the response error body in either validateResponse or handleResponseException . Is there a...
Read more >[Solved]-Parsing an error body in a ktor HTTPClient-kotlin
1. Define your model class for error. In my case it was something like · 2. Call the API · 1. val res...
Read more >WebSockets - 服务器
An exception will be thrown while receiving a Frame if the client closes the connection explicitly or the TCP socket is closed. So...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed since
1.4.3
@minogin I just encountered the same issue, luckily there is a work-around. While
response.readText()
throws an exception, you should still be able to useresponse.readBytes()
call and convert it to text or deserialize to JSON response.