Skip to content

Commit d17b3d9

Browse files
marychattee5l
authored andcommitted
KTOR-6064 Fix documentation and message of NoTransformationFoundException (#3733)
(cherry picked from commit 5307e6c)
1 parent d720899 commit d17b3d9

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

ktor-client/ktor-client-core/common/src/io/ktor/client/call/HttpClientCall.kt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package io.ktor.client.call
77
import io.ktor.client.*
88
import io.ktor.client.request.*
99
import io.ktor.client.statement.*
10+
import io.ktor.http.*
1011
import io.ktor.http.content.*
1112
import io.ktor.util.*
1213
import io.ktor.util.reflect.*
@@ -183,19 +184,24 @@ public class ReceivePipelineException(
183184
) : IllegalStateException("Fail to run receive pipeline: $cause")
184185

185186
/**
186-
* Exception representing the no transformation was found.
187-
* It includes the received type and the expected type as part of the message.
187+
* Exception represents the inability to find a suitable transformation for the received body from
188+
* the resulted type to the expected by the client type.
189+
*
190+
* You can read how to resolve NoTransformationFoundException at [FAQ](https://ktor.io/docs/faq.html#no-transformation-found-exception)
188191
*/
189-
@Suppress("KDocMissingDocumentation")
190192
public class NoTransformationFoundException(
191193
response: HttpResponse,
192194
from: KClass<*>,
193195
to: KClass<*>
194196
) : UnsupportedOperationException() {
195-
override val message: String? = """No transformation found: $from -> $to
196-
|with response from ${response.request.url}:
197-
|status: ${response.status}
198-
|response headers:
199-
|${response.headers.flattenEntries().joinToString { (key, value) -> "$key: $value\n" }}
200-
""".trimMargin()
197+
override val message: String? = """
198+
Expected response body of the type '$to' but was '$from'
199+
In response from `${response.request.url}`
200+
Response status `${response.status}`
201+
Response header `ContentType: ${response.headers[HttpHeaders.ContentType]}`
202+
Request header `Accept: ${response.request.headers[HttpHeaders.Accept]}`
203+
204+
You can read how to resolve NoTransformationFoundException at FAQ:
205+
https://ktor.io/docs/faq.html#no-transformation-found-exception
206+
""".trimIndent()
201207
}

0 commit comments

Comments
 (0)