[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,33 +413,35 @@ import com.squareup.moshi.adapter
// TODO: handle specific mapping types. e.g. Map<int, Class<?>>
@Suppress("UNNECESSARY_SAFE_CALL")
return when {
response.isRedirect -> Redirection(
response.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
response.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap()
)
response.isInformational -> Informational(
response.message{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
response.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
response.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap()
)
response.isSuccessful -> Success(
responseBody(response.body{{#jvm-okhttp3}}(){{/jvm-okhttp3}}, accept),
response.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
response.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap()
)
response.isClientError -> ClientError(
response.message{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
response.body{{#jvm-okhttp3}}(){{/jvm-okhttp3}}?.string(),
response.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
response.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap()
)
else -> ServerError(
response.message{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
response.body{{#jvm-okhttp3}}(){{/jvm-okhttp3}}?.string(),
response.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
response.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap()
)
return response.use {
when {
it.isRedirect -> Redirection(
it.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
it.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap()
)
it.isInformational -> Informational(
it.message{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
it.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
it.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap()
)
it.isSuccessful -> Success(
responseBody(it.body{{#jvm-okhttp3}}(){{/jvm-okhttp3}}, accept),
it.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
it.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap()
)
it.isClientError -> ClientError(
it.message{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
it.body{{#jvm-okhttp3}}(){{/jvm-okhttp3}}?.string(),
it.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
it.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap()
)
else -> ServerError(
it.message{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
it.body{{#jvm-okhttp3}}(){{/jvm-okhttp3}}?.string(),
it.code{{#jvm-okhttp3}}(){{/jvm-okhttp3}},
it.headers{{#jvm-okhttp3}}(){{/jvm-okhttp3}}.toMultimap()
)
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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