From d17b3d987e7583a3d3d6cf289a431ac9ecb8f68f Mon Sep 17 00:00:00 2001 From: Mariia Skripchenko <61115099+marychatte@users.noreply.github.com> Date: Tue, 22 Aug 2023 10:29:14 +0200 Subject: [PATCH] KTOR-6064 Fix documentation and message of NoTransformationFoundException (#3733) (cherry picked from commit 5307e6cdf5f43c7326c0d32c2ef6a186c2866f24) --- .../src/io/ktor/client/call/HttpClientCall.kt | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/ktor-client/ktor-client-core/common/src/io/ktor/client/call/HttpClientCall.kt b/ktor-client/ktor-client-core/common/src/io/ktor/client/call/HttpClientCall.kt index a8a9a8ca074..58608d8033c 100644 --- a/ktor-client/ktor-client-core/common/src/io/ktor/client/call/HttpClientCall.kt +++ b/ktor-client/ktor-client-core/common/src/io/ktor/client/call/HttpClientCall.kt @@ -7,6 +7,7 @@ package io.ktor.client.call import io.ktor.client.* import io.ktor.client.request.* import io.ktor.client.statement.* +import io.ktor.http.* import io.ktor.http.content.* import io.ktor.util.* import io.ktor.util.reflect.* @@ -183,19 +184,24 @@ public class ReceivePipelineException( ) : IllegalStateException("Fail to run receive pipeline: $cause") /** - * Exception representing the no transformation was found. - * It includes the received type and the expected type as part of the message. + * Exception represents the inability to find a suitable transformation for the received body from + * the resulted type to the expected by the client type. + * + * You can read how to resolve NoTransformationFoundException at [FAQ](https://ktor.io/docs/faq.html#no-transformation-found-exception) */ -@Suppress("KDocMissingDocumentation") public class NoTransformationFoundException( response: HttpResponse, from: KClass<*>, to: KClass<*> ) : UnsupportedOperationException() { - override val message: String? = """No transformation found: $from -> $to - |with response from ${response.request.url}: - |status: ${response.status} - |response headers: - |${response.headers.flattenEntries().joinToString { (key, value) -> "$key: $value\n" }} - """.trimMargin() + override val message: String? = """ + Expected response body of the type '$to' but was '$from' + In response from `${response.request.url}` + Response status `${response.status}` + Response header `ContentType: ${response.headers[HttpHeaders.ContentType]}` + Request header `Accept: ${response.request.headers[HttpHeaders.Accept]}` + + You can read how to resolve NoTransformationFoundException at FAQ: + https://ktor.io/docs/faq.html#no-transformation-found-exception + """.trimIndent() }