Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response interceptor is not intercepting response #2503

Open
mfanegg opened this issue Aug 8, 2024 · 5 comments
Open

Response interceptor is not intercepting response #2503

mfanegg opened this issue Aug 8, 2024 · 5 comments
Labels
feedback provided Feedback has been provided to the author

Comments

@mfanegg
Copy link

mfanegg commented Aug 8, 2024

(version 11.10)

Hey team,

I need to intercept a 409 so that my service sees it as a 200. From what I've scraped from the internet and the docs, you need to override aroundDecode, so my simple response interceptor looks something like this:

static class MyResponseInterceptor implements ResponseInterceptor {
    @Override
    public Object aroundDecode(final InvocationContext invocationContext) {
        final Response response = invocationContext.response();
        if (response.status() == 409) {
            final Response newResponse = response.toBuilder().status(200).build();
            return invocationContext.decoder().decode(newResponse, invocationContext.returnType());
        }
        return invocationContext.proceed();
    }
}

This doesn't actually do anything when I add it to my connector builder with .responseInterceptor(new MyResponseInterceptor()). I've tried using debugging and print statements, and it doesn't seem to actually hit my custom aroundDecode at all.

What am I doing wrong? Or perhaps I am misunderstanding the purpose of response interceptors?

Also, it would be fantastic if an example of a from-scratch response interceptor was added to the README. The README just tells us that it is possible, and gives us an example of a prebuilt response interceptor (side note, the RedirectionInterceptor that the README says Feign includes is not actually included with the package -- auto-import does not resolve it, and I'm unable to find it anywhere in version 11.10)

@derklaro
Copy link
Contributor

The latest version is 13.3; this version actually includes the RedirectionInterceptor and the aroundDecode method does not exist (anymore?): https://github.com/OpenFeign/feign/blob/master/core/src/main/java/feign/ResponseInterceptor.java

Your use case should be doable using a custom response interceptor in 13.3. Just return the value you want from intercept in case of your 409 status or call chain.next(invocationContext) if you don't want to handle the response code. You can register multiple interceptors into one feign builder.

Maybe you're including the wrong version? Should be io.github.openfeign:<component>:13.3: https://mvnrepository.com/search?q=io.github.openfeign

@mfanegg
Copy link
Author

mfanegg commented Aug 12, 2024

@derklaro

Thank you for the response. I mentioned in my original post that we are using version 11.10. Do you know how to handle my use case in that version?

I know that we should update to 13.3 -- that work is being tracked separately. We're not ready to do that update right now.

@derklaro
Copy link
Contributor

Ah, okay. I was just confused because you mentioned RedirectionInterceptor from the 13.3 readme, which is not mentioned in the 11.10 readme. I have no experience with the old version so I can not help, sorry.

@mfanegg
Copy link
Author

mfanegg commented Aug 12, 2024

Ah, my bad. I've been reading the 13.3 readme.

Upon reading the 11.10 readme, I see it does not appear to mention response interception at all. I suspect it isn't officially supported then / fleshed out, even if we're able to add them with responseInterceptor.

@kdavisk6
Copy link
Member

@mfanegg is correct. You will need to use a version of Feign with interceptor support.

@kdavisk6 kdavisk6 added feedback provided Feedback has been provided to the author labels Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feedback provided Feedback has been provided to the author
Projects
None yet
Development

No branches or pull requests

3 participants