Why ```expectSuccess = false``` not working at 1.2...
# ktor
f
Why
Copy code
expectSuccess = false
not working at 1.2.2? On Ktor multiplatform I catch Platform exception I tried the following options:
Copy code
HttpClient {
            expectSuccess = false
and
Copy code
HttpClient {
HttpResponseValidator {
                validateResponse {response ->
                    if (response.status.value!=200) {
                        throw ResponseException(response)
                    }
                }

            }
And
Copy code
ResponseException
not catched. Only
Copy code
Exception
not Solved 😞
e
Hi @Fail, could you provide the exception?
f
Connection refused
Copy code
[DefaultDispatcher-worker-2] INFO io.ktor.client.HttpClient - METHOD: HttpMethod(value=GET)
W/System.err: [DefaultDispatcher-worker-2] INFO io.ktor.client.HttpClient - COMMON HEADERS
    [DefaultDispatcher-worker-2] INFO io.ktor.client.HttpClient - -> Accept: application/json
W/System.err: [DefaultDispatcher-worker-2] INFO io.ktor.client.HttpClient - -> Accept-Charset: UTF-8
    [DefaultDispatcher-worker-2] INFO io.ktor.client.HttpClient - CONTENT HEADERS
    [DefaultDispatcher-worker-2] INFO io.ktor.client.HttpClient - BODY Content-Type: null
    [DefaultDispatcher-worker-2] INFO io.ktor.client.HttpClient - BODY START
W/System.err: [DefaultDispatcher-worker-2] INFO io.ktor.client.HttpClient - BODY END
W/System.err: [DefaultDispatcher-worker-7] INFO io.ktor.client.HttpClient - RESPONSE: 400 Bad Request
    [DefaultDispatcher-worker-7] INFO io.ktor.client.HttpClient - METHOD: HttpMethod(value=GET)
W/System.err: [DefaultDispatcher-worker-2] INFO io.ktor.client.HttpClient - REQUEST: <http://localhost/>
W/System.err: [DefaultDispatcher-worker-2] INFO io.ktor.client.HttpClient - METHOD: HttpMethod(value=GET)
W/System.err: [DefaultDispatcher-worker-2] INFO io.ktor.client.HttpClient - COMMON HEADERS
W/System.err: [DefaultDispatcher-worker-2] INFO io.ktor.client.HttpClient - -> Accept: application/json
    [DefaultDispatcher-worker-2] INFO io.ktor.client.HttpClient - -> Accept-Charset: UTF-8
    [DefaultDispatcher-worker-2] INFO io.ktor.client.HttpClient - CONTENT HEADERS
W/System.err: [DefaultDispatcher-worker-2] INFO io.ktor.client.HttpClient - BODY Content-Type: null
    [DefaultDispatcher-worker-2] INFO io.ktor.client.HttpClient - BODY START
    [DefaultDispatcher-worker-2] INFO io.ktor.client.HttpClient - BODY END
W/System.err: [DefaultDispatcher-worker-2] INFO io.ktor.client.HttpClient - REQUEST <http://localhost/> failed with exception: java.net.ConnectException: Connection refused
my clientCreation:
Copy code
fun getClient(apiSerializer: KotlinxSerializer?): HttpClient {
        return HttpClient {
            expectSuccess = true

            HttpResponseValidator {
                validateResponse { response ->
                    val statusCode = response.status.value
                    when (statusCode) {
                        in 300..399 -> throw RedirectResponseException(response)
                        in 400..499 -> throw ClientRequestException(response)
                        in 500..599 -> throw ServerResponseException(response)
                    }

                    if (statusCode >= 600) {
                        throw ResponseException(response)
                    }
                }
            }

            if (TrendSession.instance.debugNetworkRequest) {
                install(Logging) {
                    logger = Logger.DEFAULT
                    level = LogLevel.ALL
                }
            }

            if (apiSerializer!=null) {
                install(JsonFeature) {
                    serializer = apiSerializer
                }
            }

        }
    }