russhwolf
04/23/2022, 3:36 AM@Test
fun errorTest() = runTest {
val engine = MockEngine {
respondError(HttpStatusCode.NotFound)
}
val httpClient = HttpClient(engine) {
install(ContentNegotiation) {
json()
}
}
assertFailsWith<ClientRequestException> { httpClient.get("<https://example.com/>").body<Message>() }
}
@Serializable
data class Message(val data: String)
In 2.0.0 the test fails with Expected an exception of class io.ktor.client.plugins.ClientRequestException to be thrown, but was io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteBufferChannel
. It seems like the http client is attempting to deserialize the error response rather than throwing due to the unsuccessful status code. Was there a deliberate behavior change here or is this a bug?expectSuccess
changed and I missed that.