Skip to content

Commit

Permalink
[kotlin] Fix a leak in the ApiClient (#18997)
Browse files Browse the repository at this point in the history
  • Loading branch information
gosusnp authored Jun 23, 2024
1 parent 640ef9d commit 4e89436
Show file tree
Hide file tree
Showing 21 changed files with 609 additions and 567 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
}
}

Expand Down
Loading

0 comments on commit 4e89436

Please sign in to comment.