|
|
@@ -6,7 +6,6 @@ import io.ktor.client.HttpClient
|
|
|
import io.ktor.client.call.body
|
|
|
import io.ktor.client.engine.okhttp.OkHttp
|
|
|
import io.ktor.client.plugins.ClientRequestException
|
|
|
-import io.ktor.client.plugins.HttpRequestRetry
|
|
|
import io.ktor.client.plugins.HttpResponseValidator
|
|
|
import io.ktor.client.plugins.HttpTimeout
|
|
|
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
|
|
@@ -24,7 +23,6 @@ val KtorClient = HttpClient(OkHttp) {
|
|
|
if (it) Global.serverUrl else "${Global.serverUrl}/"
|
|
|
})
|
|
|
}
|
|
|
- install(HttpRequestRetry)
|
|
|
install(HttpTimeout) {
|
|
|
requestTimeoutMillis = 180000
|
|
|
connectTimeoutMillis = 180000
|
|
|
@@ -47,4 +45,35 @@ val KtorClient = HttpClient(OkHttp) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+val KtorClient1 = HttpClient(OkHttp) {
|
|
|
+ defaultRequest {
|
|
|
+ Global.load()
|
|
|
+ url(Global.serverUrl.endsWith("/").let {
|
|
|
+ if (it) Global.serverUrl else "${Global.serverUrl}/"
|
|
|
+ })
|
|
|
+ }
|
|
|
+ install(HttpTimeout) {
|
|
|
+ requestTimeoutMillis = 5000
|
|
|
+ connectTimeoutMillis = 5000
|
|
|
+ socketTimeoutMillis = 5000
|
|
|
+ }
|
|
|
+ install(Resources)
|
|
|
+ install(ContentNegotiation) {
|
|
|
+ json(Json {
|
|
|
+ prettyPrint = true
|
|
|
+ isLenient = true
|
|
|
+ ignoreUnknownKeys = true
|
|
|
+ explicitNulls = false
|
|
|
+ })
|
|
|
+ }
|
|
|
+ HttpResponseValidator {
|
|
|
+ validateResponse { response ->
|
|
|
+ if (response.status.value !in 200..299) {
|
|
|
+ val error = response.body<ErrorResponse>()
|
|
|
+ throw ClientRequestException(response, error.message ?: "Unknown error")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|