openfeign / feign-annotation-error-decoder Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
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.
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
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();
}
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();
}
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,
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
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
`
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).
Ok as i can see, you have already migrated the minor api change. When do you think the 1.3.1 will be released?
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.
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?
initial commit of annotation error decoder
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.
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:
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.
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.
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
}
}
}
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.