question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OptionalAwareDecoder in feign core?

See original GitHub issue

Hej again, How are the chances of getting a “feign-guava-optional” module (or similar) into feign that knows about 404-decoding Guava Optional? Such a module would have a Guava dependency and only make sense where decode404 is enabled. R.

/**
 * Decorates a Feign {@link Decoder} such that it returns {@link Optional#absent} when observing an HTTP 404 error code
 * for a method with {@link Type} {@link Optional}. Propagates the exception returned by the given {@link ErrorDecoder}
 * in case the response is 404 for a non-Optional method.
 */
public final class OptionalAwareDecoder implements Decoder {

    private final Decoder delegate;
    private final ErrorDecoder errorDecoder;

    public OptionalAwareDecoder(Decoder delegate, ErrorDecoder errorDecoder) {
        this.delegate = delegate;
        this.errorDecoder = errorDecoder;
    }

    @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 {
                throw Throwables.propagate(errorDecoder.decode(null, response));
            }
        } else {
            return delegate.decode(response, type);
        }
    }
}

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:6
  • Comments:22 (18 by maintainers)

github_iconTop GitHub Comments

12reactions
greyfairercommented, Jan 19, 2016

+1 for me, allthough I need support for Java 8 Optional, too.

1reaction
ilaboriecommented, Apr 17, 2016

+1 but it’s require a JDK 8

Read more comments on GitHub >

github_iconTop Results From Across the Web

Request.Options (Feign Core 12.1 API) - javadoc.io
Creates a new Options instance. Parameters: connectTimeoutMillis - connection timeout in milliseconds. readTimeoutMillis - read timeout in milliseconds.
Read more >
feign.Types.getRawType java code examples - Tabnine
Best Java code snippets using feign.Types.getRawType (Showing top 14 results ... origin: com.netflix.feign/feign-core ... OptionalAwareDecoder.decode(...).
Read more >
Spring Cloud OpenFeign
Feign is a declarative web service client. It makes writing web service clients easier. To use Feign create an interface and annotate it....
Read more >
io.github.openfeign : feign-core - Maven Central
Version Updated OSS Index V: ‎ 12.1 Updated: 18‑Nov‑2022 open_in_new V: ‎ 12.0 Updated: 31‑Oct‑2022 open_in_new V: ‎ 11.10 Updated: 21‑Sep‑2022 open_in_new
Read more >
Intro to Feign | Baeldung
This article introduces Feign, a declarative HTTP client that simplifies ... Besides the feign-core dependency (which is also pulled in), ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found