GithubHelp home page GithubHelp logo

Comments (7)

saintf avatar saintf commented on June 16, 2024

Hey @chrisob55 - I'll take a look but I'll need to try to reproduce the issue. Do you by any chance have a zip of a sample of the issue you're seeing? Just trying to reproduce in my IDE.

Thanks,
-Fernando

from feign-annotation-error-decoder.

lucasm0ta avatar lucasm0ta commented on June 16, 2024

Hello, I've found the same problem.
Here is a small example to give the idea of what I've tried to do, but failed. All exceptions defined on the @ErrorHandling extends AbstractRequestException. But all requests that mach the error codes fall into the catch of the FeignException.

Client.java

@ErrorHandling(codeSpecific =
    {
        @ErrorCodes( codes = {400}, generate = PayloadException.class),
        @ErrorCodes( codes = {403}, generate = ForbiddenException.class),
        @ErrorCodes( codes = {404}, generate = UnknownResourceException.class),
    },
    defaultException = PayloadException.class
)
@FeignClient(value = "api", url = "${api.path}",
    configuration = ClientConfiguration.class)
public interface Client {

    @RequestMapping(method = RequestMethod.PUT, value = "/path", consumes = "application/json")
    String create(@RequestBody final String payload);

}

Service.java

@RestController
@RequestMapping(path = "/test")
public class Service {

    private final Client client;

    @Autowired
    public Service(final Client client) {
        this.client = client;
    }

    @GetMapping(path = "/a")
    @ResponseBody
    public String makeRequest(@RequestParam final String id) {
        try {
            String body = "";
            externalHouse = this.client.create(body);
        } catch (AbstractRequestException e) {
            log.error(e.getMessage());
        } catch (FeignException e) {
            log.error(e.getMessage());
        }
    }
}

Also, in the ClientConfiguration class, I've defined the following:

    @Bean
    public ErrorDecoder errorDecoder() {
        return AnnotationErrorDecoder.builderFor(Client.class).build();
    }

from feign-annotation-error-decoder.

saintf avatar saintf commented on June 16, 2024

from feign-annotation-error-decoder.

StefanFellinger avatar StefanFellinger commented on June 16, 2024

Hi @lucasm0ta ,

maybe you have solved the problem yourself, since it's a long time ago since you've opened this ticket.

The AnnotationErrorDecoder requires methods to be annotated with @errorHandling to kick in. So if you annotate your Method simple with @errorHandling() it will work.

from feign-annotation-error-decoder.

lucasm0ta avatar lucasm0ta commented on June 16, 2024

It has been quite a long time! I really lost track of this issue as I used another approach at the time. Thank you for the note on this issue. While I'm not currently working with the code with said problem, I hope it helps other users 😄. In case I get back to it, I'll give it a try

from feign-annotation-error-decoder.

jnm-ronquillo avatar jnm-ronquillo commented on June 16, 2024

Hello guys I am getting this error when using
feign-annotation-error-decoder:1.3.0
spring-cloud-starter-openfeign:2.2.3.RELEASE

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    feign.error.ExceptionGenerator.<clinit>(ExceptionGenerator.java:44)

The following method did not exist:

    feign.Request.create(Lfeign/Request$HttpMethod;Ljava/lang/String;Ljava/util/Map;Lfeign/Request$Body;)Lfeign/Request;     

My Error decoder is as following:

@Bean
public ErrorDecoder errorDecoder() {
    return AnnotationErrorDecoder.builderFor(Client.class).build();
 }

My problem is that feign returns an empty body for 401 response (this is my testing use case, the service returns a custom response) I don't know all the error codes the service will return. I also tried creating a custom ErrorDecoder but inside the decode method the body of the Response object is also null.

public ErrorDecoder errorDecoder() {
    return new FeignClientExceptionErrorDecoder();
}

I'd like to know if feign-annotation-error-decoder works for you guys with the latest version of Spring Cloud. Mi intention is to propagate the response for http error status codes. This json response change for the same error code according to the input data.

Greetings.

from feign-annotation-error-decoder.

brunapereira avatar brunapereira commented on June 16, 2024

I'm facing the same error as @jnm-ronquillo. Any thoughts on that?

EDIT: I was able to make it work, by using these specific versions:

implementation("org.springframework.cloud:spring-cloud-starter-openfeign:2.2.2.RELEASE")
implementation("io.github.openfeign:feign-annotation-error-decoder:1.3.0")
implementation("io.github.openfeign:feign-core:10.2.0")

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.