GithubHelp home page GithubHelp logo

Comments (5)

saintf avatar saintf commented on September 21, 2024

If you take a look at https://github.com/OpenFeign/feign/blob/master/core/src/main/java/feign/SynchronousMethodHandler.java (notice it's a final class/etc) you'll see that at method public Object invoke(Object[] argv) (line 74 at the time of this note) there's an attempt to decode the response/etc. That's where RetryableException gets caught. It then hands the retry to the Retryer (regardless of what Retryer you've configured).

That means that all your exception needs to do to get passed to the Retryer is extend RetryableException - MyAwesomeRetryableException extends RetryableException.

You can then basically implement whatever you want as that exception and override the retryAfter() method to return whatever date you so desire to retry after - wether you choose to use the headers, or just a hard-coded value (timeOfExceptionCreation + 1000 for example) - it's all completely up to you :).

Let me know if that answers your question (and if so - please close ;))

Thanks,
-Fernando

from feign-annotation-error-decoder.

sebeard avatar sebeard commented on September 21, 2024

I think so it pretty much ties up what I already had. The problem is that the RetryDecoder in feign.codec.ErrorDecoder only has package local visibility (see https://github.com/OpenFeign/feign/blob/master/core/src/main/java/feign/codec/ErrorDecoder.java). To use this the exception I create would need to move my exception class to feign.codec OR duplicate the RetryDecoder into my own code base, which is a little frustrating.

Here's what I have which works;

package feign.codec;

import feign.RetryableException;
import feign.codec.ErrorDecoder.RetryAfterDecoder;

import java.util.Collection;
import java.util.Map;

import static feign.Util.RETRY_AFTER;

public abstract class RetryAfterException extends RetryableException {

    private static final long serialVersionUID = 1L;

    public RetryAfterException(int code, Map<String, Collection<String>> headers, String body) {
        super(code, body, null, new RetryAfterDecoder().apply(retryAfterOrNull(headers)));
    }

    private static <T> T retryAfterOrNull(Map<String, Collection<T>> map) {
        if (map.containsKey(RETRY_AFTER) && !map.get(RETRY_AFTER).isEmpty()) {
            return map.get(RETRY_AFTER).iterator().next();
        }
        return null;
    }


}

I guess the best solution would be to raise an issue on feign itself to get that access opened up a little more.

Thanks for the support @saintf

from feign-annotation-error-decoder.

saintf avatar saintf commented on September 21, 2024

No prob. I'm now confused as to what it was you were trying to achieve... It isn't clear to me.

When do you want to retry and how?

from feign-annotation-error-decoder.

saintf avatar saintf commented on September 21, 2024

(hit submit too soon...)

The RetryDecoder is an error decoder (just like the annotation-error-decoder is one). Feign only lets you pick one. I'd argue rather than using the RetryDecoder, you'd use this one to generate an exception that consumes the response and sets the retryAfter.

I think what you're trying to say is that there's some functionality (decoding the header) that is already written in the RetryDecoder that would wouldn't want to duplicate (specifically, reading the header).

I wonder if it makes sense to enhance that functionality to move to either the RetryableException (so that it offers it by consuming the response) or if we perhaps somehow allow for that functionality to exist in the annotation-error-decoder (though that doesn't feel completely like the right place as reading those headers is a more generic task - even if it did offer some extra value for the annotation decoder).

Thoughts?

from feign-annotation-error-decoder.

hellboy81 avatar hellboy81 commented on September 21, 2024

serialVersionUID should be unique for each exception class?

from feign-annotation-error-decoder.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.