Fail
07/26/2019, 2:27 PMexpectSuccess = false
not working at 1.2.2? On Ktor multiplatform I catch Platform exception
I tried the following options:
HttpClient {
expectSuccess = false
and
HttpClient {
HttpResponseValidator {
validateResponse {response ->
if (response.status.value!=200) {
throw ResponseException(response)
}
}
}
And ResponseException
not catched. Only Exception
not Solved 😞e5l
07/26/2019, 2:28 PMFail
07/26/2019, 2:41 PMFail
07/26/2019, 2:41 PM[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
Fail
07/26/2019, 3:42 PMfun 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
}
}
}
}