[kotlin] Fix a leak in the ApiClient (#18997)

This commit is contained in:
Jimmy Ma 2024-06-23 02:17:05 -07:00 committed by GitHub
parent 640ef9d944
commit 4e89436177
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 609 additions and 567 deletions

View File

@ -413,35 +413,37 @@ import com.squareup.moshi.adapter
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}}, it.isRedirect -> Redirection(
response.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap() it.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
it.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message{{#jvm-okhttp3}}(){{/jvm-okhttp3}}, it.message{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
response.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}}, it.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
response.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap() it.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body{{#jvm-okhttp3}}(){{/jvm-okhttp3}}, accept), responseBody(it.body{{#jvm-okhttp3}}(){{/jvm-okhttp3}}, accept),
response.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}}, it.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
response.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap() it.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message{{#jvm-okhttp3}}(){{/jvm-okhttp3}}, it.message{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
response.body{{#jvm-okhttp3}}(){{/jvm-okhttp3}}?.string(), it.body{{#jvm-okhttp3}}(){{/jvm-okhttp3}}?.string(),
response.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}}, it.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
response.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap() it.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message{{#jvm-okhttp3}}(){{/jvm-okhttp3}}, it.message{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
response.body{{#jvm-okhttp3}}(){{/jvm-okhttp3}}?.string(), it.body{{#jvm-okhttp3}}(){{/jvm-okhttp3}}?.string(),
response.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}}, it.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
response.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap() it.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -202,35 +202,37 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -202,35 +202,37 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -202,35 +202,37 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -202,35 +202,37 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -202,35 +202,37 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -202,35 +202,37 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -220,35 +220,37 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -220,35 +220,37 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -226,35 +226,37 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -234,35 +234,37 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -221,35 +221,37 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -221,35 +221,37 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -221,35 +221,37 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -202,35 +202,37 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -221,35 +221,37 @@ internal open class ApiClient(val baseUrl: String, val client: OkHttpClient = de
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -221,35 +221,37 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -221,35 +221,37 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -221,35 +221,37 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -202,35 +202,37 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""

View File

@ -221,35 +221,37 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
// TODO: handle specific mapping types. e.g. Map<int, Class<?>> // TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL") @Suppress("UNNECESSARY_SAFE_CALL")
return when { return response.use {
response.isRedirect -> Redirection( when {
response.code, it.isRedirect -> Redirection(
response.headers.toMultimap() it.code,
it.headers.toMultimap()
) )
response.isInformational -> Informational( it.isInformational -> Informational(
response.message, it.message,
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isSuccessful -> Success( it.isSuccessful -> Success(
responseBody(response.body, accept), responseBody(it.body, accept),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
response.isClientError -> ClientError( it.isClientError -> ClientError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
else -> ServerError( else -> ServerError(
response.message, it.message,
response.body?.string(), it.body?.string(),
response.code, it.code,
response.headers.toMultimap() it.headers.toMultimap()
) )
} }
} }
}
protected fun parameterToString(value: Any?): String = when (value) { protected fun parameterToString(value: Any?): String = when (value) {
null -> "" null -> ""