GithubHelp home page GithubHelp logo

feign-annotation-error-decoder's People

Contributors

adriancole avatar karlmuscat avatar saintf avatar simy4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

feign-annotation-error-decoder's Issues

[Question] [support needed] Error Response Body is empty

I am trying to decode error response body but got always null:

code specific ErrorCodes error Exception classes are generated properly but with empty body:

image

Feign's OkHttp client is used.

Where is my bad?

Used versions:

  • Feign: 10.2.3
  • annotatiion-error-decoder: 1.2.0

P.S. Another developers from UA reported feign-error-decoder does not work properly.

See also my question in chat.

Add option to pass methodKey to exception constructor

I'm attempting to replace a custom ErrorDecoder with annotations and I utilize the methodKey parameter that is provided to ErrorDecoder::decode. Is there a way to get this in the exception constructor like body and headers?

[Question] Ignore custom exception constructors at startup

Version
1.3.0

Problem
Hi,
I'm using the @FeignExceptionConstructor with a custom exception like:
@FeignExceptionConstructor
public ExternalApiException(final Response response) {
if(response != null){
// extract info from response
log.error(...) // print the status, body and other stuff extracted from response
}
}

I know in your documentation is specified that

It's worth noting that at setup/startup time, the generators are checked with a null value of the body. If you don't do the null-checker, you'll get an NPE and startup will fail.

but this is annoying because the response will not be null and it will print multiple ERROR messages into logs when the app starts due to the 'generators checking' and they are not really errors.

Question
Is there a way of disabling this checking? Is this checking of constructors mandatory? I just don't want to fill the logs with error messages (that are not really error messages) because of it.

Thank you.

Meta-annotation support

Mainly in combination with spring-cloud-openfeign it would be really helpfull to have support for meta-annotations.
This will reduce the amount of annotations in the interface.

The idea is to have a custom annotation which combines the @RequestMapping annotations with the @ErrorHandling annotation on a method/class level. the SpringDecoder is able to work with the meta-annotations already so it is more consistent to have also @ErrorHandling working in a meta-annotation

e.g.

@ErrorHandling(codeSpecific =
    {
        @ErrorCodes( codes = {401}, generate = UnAuthorizedException.class),
        @ErrorCodes( codes = {403}, generate = ForbiddenException.class),
        @ErrorCodes( codes = {404}, generate = UnknownItemException.class),
    },
    defaultException = MethodLevelDefaultException.class
)
@RequestMapping(method = RequestMethod.GET, consumes = APPLICATION_CBOR_VALUE, produces = APPLICATION_CBOR_VALUE)
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface GetMappingWithErrorHandling {
    @AliasFor(annotation = RequestMapping.class)
    String[] path() default {};
}

and so it is possible to have in the interface only one annotation

public interface GitHub {
    @GetMappingWithErrorHandling(path="https://github.com/projects"
    List<Contributor> projects();
}

Upgrade 11.0

feign core 11.0 upgrade

TEST_RESPONSE = Response.builder() .status(500) .body((Response.Body) null) .headers(testHeaders) .request(Request.create(Request.HttpMethod.GET, "http://test", testHeaders, null)) .build(); }

Request.create ERROR

When will versions be compatible?

project Run Error log
`
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;

The method's class, feign.Request, is available from the following locations:

jar:file:/Users/sinsanghun/.gradle/caches/modules-2/files-2.1/io.github.openfeign/feign-core/11.0/29fd8a94cae3f0450894b3875398d57222fce03c/feign-core-11.0.jar!/feign/Request.class

The class hierarchy was loaded from the following locations:

feign.Request: file:/Users/sinsanghun/.gradle/caches/modules-2/files-2.1/io.github.openfeign/feign-core/11.0/29fd8a94cae3f0450894b3875398d57222fce03c/feign-core-11.0.jar

Action:

Correct the classpath of your application so that it contains a single, compatible version of feign.Request

Process finished with exit code 1
`

with move to feign-core 10.x.x, support capturing the request in Exception constructors

Feign core 10.X.X allows capturing the Request made from a Response - meaning that we can include the original request into an exception if required.

The requirement here is to detect if one of the parameters in the constructor for the exception is of type Request, and if so, put the original request into that field.

In a later iteration we can ask people want us to do more parsing (like only include request headers based on a @RequestHeaders tag or only the request body based on a @RequestBody tag) - though for now we expect handing over the Request itself is probably more than enough (would want to see usecases for anything further).

Hence - put simply - when an exception is defined as:

public class MyException {
   
   public MyException(Request request) {
      ...
   }
}

then the AnnotationErrorDecoder should inject the Request.

[Question] - Annotation based Retry After Exception

In your README you give an example of RetryAfterCertainTimeException. How does this work with Feign's RetryableException? I'm trying to implement a RetryAfterException that gets automatically retried, but without duplicating Feign's RetryAfterDecoder (or putting my exception class in the feign.codec package).

ErrorHandlerMap empty if only define annotation class

If define error handler only a class annotation, the member value errorCodes return a empy collection of error codes and the builder only build the default generic error

public class AnnotationErrorDecoder implements ErrorDecoder {
private final Map<String, MethodErrorHandler> errorHandlerMap;

errorhandlermap have a empty map of errros

Upgrade to Feign 10.10.x

Ok as i can see, you have already migrated the minor api change. When do you think the 1.3.1 will be released?

AnnotationErrorDecoder throws IllegalStateException on validateGeneratorCanBeUsedToGenerateExceptions with null body and complex body decoder

Whenever you're trying to set up a complex body decoder (like SpringDecoder) the validation step passes null for response body which causes body decoder to throw NPE, which propagates as IllegalStateException. Setting the response body as Optional doesn't do anything because Optional type is not accounted for processing in feign.optionals.OptionalDecoder (Something about type parametricity details missing).

UPD: Injection of raw response entity doesn't work as well.

Use with Spring Cloud

There seems to be an issue when trying to use this within Spring Cloud/Eureka setup. Using the @FeignClient annoation

@FeignClient(name = "myResource", url = "${my.endpoint}", configuration = MyResourceConfig.class)

Defining the AnnotationErrorDecoder in the configuration means it doesn't work. Is there any there way of defining an AnnotationErrorDecoder (ideally leaving out the builderFor(XXXX.class) as this can cause a circular reference?

Thanks,

Use own ExceptionGenerator

Hi,

I would like to use my own ExceptionGenerator to be free to add another field (requestUrl) to my exception. Could you adapt the AnnotationErrorDecoder to be able to pass an ExceptionGeneratorBuilder to this class?

I thought about adding a new method

public Builder withExceptionGeneratorBuilder(ExceptionGenerator.Builder exceptionGenerator) { this.exceptionGenerator = exceptionGenerator; return this; }

to the AnnotationErrorDecoder, but due to the current design this would lead to a lot of changes in the ExceptionGenerator and ExceptionGeneratorBuilder classes and its design.

Dont work use global interface

Hi, I'm using the annotation and I had a big problem, when I create a unique interface and try to extend it in other interfaces does not work.

Gradle dependency

Hi,

This is something quite useful for us and we are looking for a more Annotation based handling of Error Codes. Is there a Gradle dependency for this that we could use? We are using Feign with Hystrix, plugged in using OkHttp client.

Regards,
Sri

v1.0.3 does not work with feign-core 10.x.x

Upgraded my projects to JDK 11 and as a result I had to upgrade also the Spring Cloud dependencies to the Greenwich.RELEASE. The Greenwich.RELEASE upgrades the feign libraries to 10.1.0, however the feign-annotation-error-decoder, still uses 9.5.0.

The Response class in the latest feign-core library introduced a check that is breaking the ExceptionGenerator in the feign-annotation-error-decoder

The check is:
checkState(builder.request != null, "original request is required");

and this is the broken code:

static {
        Map<String,Collection<String>> testHeaders = new HashMap<String, Collection<String>>();
        testHeaders.put("TestHeader", Arrays.asList("header-value"));

        TEST_RESPONSE = Response.builder()
            .status(500)
            .body((Response.Body) null)
            .headers(testHeaders)
            .build();
    }

documentation should be explicit about the custom exception constructor contract

Documentation about custom exception de-serialization - using deserialized error response bodies - does not state anything about its contract:

class ComplexPojoException extends Exception {

    @FeignExceptionConstructor
    public ComplexPojoException(GithubExceptionResponse body) {

    }
}

it should be documented that at setup-time, feign will test the exception generators using a null body and that such a test should appear in the constructor:

class ComplexPojoException extends Exception {

    @FeignExceptionConstructor
    public ComplexPojoException(GithubExceptionResponse body) {
        if (body != null) {
            // extract data
        } else {
            // fallback code
        }
    }
}

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.