https://kotlinlang.org logo
#ktor
Title
# ktor
r

russhwolf

04/23/2022, 3:36 AM
The following test succeeded in ktor 2.0.0-beta-1
Copy code
@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?
Oh, it looks like the default for
expectSuccess
changed and I missed that.
4 Views