Skip to content

decode404 API is broken #292

@uschi2000

Description

@uschi2000

Hi @adriancole and other feign folks,

Trying to implement an "OptionalAwareJacksonDecoder", it seems that the new decode404 API is rather inflexible. Here's the scenario: Assume a server interface with two methods:

Optional<Foo> getOptionalFoo();
Foo getFoo();

, and assume a Feign client with decode404() option enabled. Now, when OptionalAwareJacksonDecoder#decode gets hit, it has to decide what to return, roughly like this:

    @Override
    public Object decode(Response response, Type type) throws IOException, FeignException {
        if (response.status() == 404) {
            if (Types.getRawType(type).equals(Optional.class)) {
                return Optional.absent();
            } else {
                // ??? should call client's ErrorDecoder and throw the error supplied, but cannot.
            }
        } else {
            return delegate.decode(response, type); // delegate to injected JacksonDecoder
        }
    }

It all works fine for the getOptionalFoo() interface, but fails for the getFoo() interface, because we should really be delegating to the configured ErrorDecoder, but cannot (even if we inject it, we're not allowed to throw here).

Thoughts?

Thanks!
Robert

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions