OpenFeign / feign

Feign makes writing java http clients easier
Apache License 2.0
9.36k stars 1.91k forks source link

Even using OptionalDecoder I get an exception on 404 #2340

Open ramgom opened 4 months ago

ramgom commented 4 months ago

Given this feign client:

`interface UserClient {

@RequestLine("GET /users/{name}")
fun getUser(@Param("name") name: String): Optional<User>

}`

val userClient = Feign.builder() .encoder(JacksonEncoder(objectMapper)) .decoder(OptionalDecoder(JacksonDecoder(objectMapper))) .target(UserClient::class.java, BASE_URL)

when I unit test this:

` WireMock.stubFor( WireMock.get("/users/test") .willReturn(WireMock.notFound()) )

    userClient.getUser("test")

`

I'm getting this exception: [404 Not Found] during [GET] to [http://localhost:7070/users/test] [UserClient#getUser(String)]: []

And I was expecting to actually get an empty optional.

gromspys commented 4 months ago

@ramgom try to use dismiss404():

val userClient = Feign.builder()
    .dismiss404()
    .encoder(JacksonEncoder(objectMapper))
    .decoder(OptionalDecoder(JacksonDecoder(objectMapper)))
    .target(UserClient::class.java, BASE_URL)

I think it should help you.