Declarative client and circuitbreaker retry won't trigger for 404 responses #11548
Replies: 4 comments 1 reply
-
Micronaut implements the same semantics as OpenFeign which doesn't regard 404 as retryable status code since it isn't an error |
Beta Was this translation helpful? Give feedback.
-
OpenFeign can be configured to treat 404 status codes as retryable though. Micronaut cannot, which is my point. The methods to do it in Micronaut are not working. ❌ custom error decoder @Singleton
public class CustomErrorDecoder implements HttpClientErrorDecoder {
@Override
public Exception decode(HttpResponse<?> response, HttpClientException exception) { //doesn't exist
if (response.getStatus().getCode() == 404) {
return new HttpClientResponseException("Resource not found", response);
}
// Default behavior for other status codes
return new HttpClientResponseException(response.getStatus().getReason(), response);
}
} ❌ global exception handler @Produces
@Singleton
@Requires(classes = {HttpClientResponseException.class, ExceptionHandler.class})
public class CustomHttpClientResponseExceptionHandler implements ExceptionHandler<HttpClientResponseException, HttpResponse<?>> {
@Override
public HttpResponse<?> handle(HttpRequest request, HttpClientResponseException exception) {
if (exception.getStatus().getCode() == 404) {
return HttpResponse.notFound("Resource not found");
}
return HttpResponse.status(exception.getStatus(), exception.getMessage());
}
} |
Beta Was this translation helpful? Give feedback.
-
probably because 404 is never treated as an error. Would require a similar configuration change to feign. |
Beta Was this translation helpful? Give feedback.
-
Thanks, but that was the predicate method above no? Which doesn't work. I'm unable to find a solution so am in the process of migrating services to use imperative method on Any thoughts/views on why none of the solutions (3) are working for the declarative http |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When using the Declarative client with circuitbreaker, a 404 response returns a
Mono.empty()
instead of throwing an exception. This prevents the circuitbreaker retry being triggered.Example client
And the predicate class:
build.gradle
api("io.micronaut.reactor:micronaut-reactor-http-client")
I tried to override this behaviour with a custom error decoder and a global exception handler, but it didn't work. How can I make the client throw an exception on a 404 response so that the circuit breaker can retry?
Beta Was this translation helpful? Give feedback.
All reactions