question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ktor-client-logging has problems handling large response content

See original GitHub issue

Ktor Version

1.0.1

Ktor Engine Used(client or server and name)

Client

JVM Version, Operating System and Relevant Context

Android

Feedback

Doing a request, if the request creates an error (Code 500) at the backend and the backend response is a large (9000+ character) error content, I would like to be able to see this in the log but currently this does not seem to be supported because no content what so ever is printed out.

Currently it will get stuck at:

INFO io.ktor.client.HttpClient - BODY Content-Type: application/json; charset=utf-8
INFO io.ktor.client.HttpClient - BODY START

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
Syroucommented, Jan 8, 2019

Added:

implementation "org.slf4j:slf4j-simple:1.6.1"

to the dependency which solved the above issue. Now I’m still stuck at:

NFO io.ktor.client.HttpClient - BODY Content-Type: application/json; charset=utf-8
INFO io.ktor.client.HttpClient - BODY START

But i’m not sure if this is an error on my side while implementing ktor or not, i’ve made a wrapper around ktor-client which ends up a builder looking like this(this is commonMain code):

        protected suspend inline fun <reified T> buildInner(): T =
                coroutineScope {
                    var deferred: Deferred<T> = GlobalScope.async {

                        val httpClient = HttpClient(mBlockHttpClientConfig)
                        return@async httpClient.request<T> {

                            method = mHttpMethod
                            url {
                                takeFrom(restUrl)
                                encodedPath = mPath
                            }
                            mContentType?.let {
                                accept(it)
                            }

                            mParameters.takeIf { it.size > 0 } ?: let {
                                mParameters.forEach { param ->
                                    parameter(param.first, param.second)
                                }
                            }
                            body = mBody
                        }
                    }
                    return@coroutineScope deferred.await()
                }

        inline fun <reified T> build(): RestResult<T> {
            var restResult: RestResult<T> = RestResult()
            GlobalScope.launch {
                try {
                    restResult.broadcastSuccess(buildInner())
                } catch (e: Exception) {
                    restResult.broadcastFailure(e)
                }
            }
            return restResult
        }
2reactions
Syroucommented, Jan 8, 2019

Updated ktor client to 1.1.1 and it now get this instead: W/System.err: SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”.

This with using:

commonMain:
implementation "io.ktor:ktor-client-logging:1.1.1"
jvmMain:
implementation "io.ktor:ktor-client-logging-jvm:1.1.1"
Read more comments on GitHub >

github_iconTop Results From Across the Web

Logging - Ktor
Ktor client provides the capability to log HTTP calls using the Logging plugin. This plugin provides different logger types for different ...
Read more >
Parsing an error body in a ktor HTTPClient - Stack Overflow
My query here is I am not able to access the response error body in either validateResponse or handleResponseException . Is there a...
Read more >
Ktor - JetBrains YouTrack
KTOR -5327 Client fails to parse response without Content-Length, Connection headers and chunked transfer encoding. 1. Bug. Server. 2.2.1. No plugin version.
Read more >
Table of Contents - Micronaut Documentation
Micronaut now supports the latest GraalVM 22.0.0.2 release. Environment Endpoint. A new API EnvironmentEndpointFilter has been created to allow applications to ...
Read more >
How to Build an Android Wellness App with the Ktor ... - Perpetio
Instead, we have something more fascinating to show — the Ktor Client dependencies ... implementation "io.ktor:ktor-client-logging:$ktor_version" // Ktor ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found