You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using Feign 11.9.1 ... (yes - a bit old I know ...)
I have an API that I can't change that returns either 200 or 202 depending on what happens on the backend. Client needs to know which response status code was returned. Body will always be empty.
What is the best way to handle this? (Using feign/kotlin)
Currently - I have something super hacky (i'm not proude of this) working - Client side I have a definition using:
@RequestLine("PUT /some/rando/api")
fun callRandoApi(
@RequestBody request: RandoRequest,
): Response<EmptyResponse>
where:
class EmptyResponse // this models an empty body just fine I guess
data class Response<T>(val status: Int, val body: T) // models passing the response code back always
and a custom decoder:
class JacksonDecoderWithStatus<T> : JacksonDecoder() {
override fun decode(response: feign.Response, type: Type): Response<T> {
// use the inner type
val innerType: Type = (type as ParameterizedTypeImpl).actualTypeArguments.first() // yuck
@Suppress("UNCHECKED_CAST")
return Response(
status = response.status(),
body = super.decode(response, innerType) as T, // somewhat - gross
)
}
}
I realize that nothing really connects the decoder type to the response inner type and I don't like using the reflect stuff directly ... ; I have a inline reified function I was playing with as well ..
It seems like there should be a more straightforward way to do this ... Am I wrong?
The text was updated successfully, but these errors were encountered:
What may be more appropriate in your case is to use a ResponseMapper. This allows you to manipulate the response before decoding. Consider using this instead, along with a simple Decoder to get this mutated feign.Response into your EmptyResponse
Using Feign 11.9.1 ... (yes - a bit old I know ...)
I have an API that I can't change that returns either 200 or 202 depending on what happens on the backend. Client needs to know which response status code was returned. Body will always be empty.
What is the best way to handle this? (Using feign/kotlin)
Currently - I have something super hacky (i'm not proude of this) working - Client side I have a definition using:
where:
and a custom decoder:
while the feign builder gets:
I realize that nothing really connects the decoder type to the response inner type and I don't like using the reflect stuff directly ... ; I have a inline reified function I was playing with as well ..
It seems like there should be a more straightforward way to do this ... Am I wrong?
The text was updated successfully, but these errors were encountered: