Kaigo
Kaigo

Reputation: 1599

How to make micronaut client return exception for 404 response instead of Mono.empty()

This micronaut client returns Mono.empty() on a 404 response, which means it doesn't trigger the circuit breaker retry

@Client("my-client")
public interface RcsCapabilityClient {
    String PATH = "/internal/v1/something";

    @Get(PATH)
    @CircuitBreaker(attempts = "${my-client-circuitBreaker.attempts}",
            delay = "${my-client-clients.circuitBreaker.delay}",
            maxDelay = "${my-client-clients.circuitBreaker.maxDelay}",
            reset = "${my-client-clients.circuitBreaker.reset}",
            predicate = MyClientRetryPredicate.class)
    Mono<SomeCustomResponse> getSomething();
}

Given predicate class

public class MyClientRetryPredicate implements RetryPredicate {
    @Override
    public boolean test(Throwable t) {
        if (t instanceof HttpClientResponseException e) {
            return switch (e.getStatus()) {
                case UNPROCESSABLE_ENTITY, BAD_REQUEST, GATEWAY_TIMEOUT, OK -> false;
                default -> true;
            };
        }

        if (t instanceof ResponseClosedException) {
            return true;
        }
        if (t instanceof HttpClientException hce) {
            return !(hce.getCause() instanceof CodecException);
        }
        return true;
    }
}

I couldn't seem to override this behaviour with a Custom decoder nor a global exception handler.

What is the best way around this when using Declarative Client?

Thanks

Upvotes: 0

Views: 38

Answers (0)

Related Questions