From 09d6ebb2de3294c41b3f7b29e408ffc681b68d32 Mon Sep 17 00:00:00 2001 From: Rui Han Date: Sat, 12 Oct 2024 15:23:50 +0800 Subject: [PATCH] Update log lever for retry (#94) * Update log lever for retry * Pass the retry error to user side --- .../util/gateway/util/WebClientAdapter.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/commonjava/util/gateway/util/WebClientAdapter.java b/src/main/java/org/commonjava/util/gateway/util/WebClientAdapter.java index c094bee..f3d800a 100644 --- a/src/main/java/org/commonjava/util/gateway/util/WebClientAdapter.java +++ b/src/main/java/org/commonjava/util/gateway/util/WebClientAdapter.java @@ -384,6 +384,7 @@ public Response intercept( @NotNull Chain chain ) throws IOException { Request req = chain.request(); Response resp = null; + IOException latestException = null; int tryCounter = 0; do { if ( resp != null ) @@ -410,23 +411,20 @@ public Response intercept( @NotNull Chain chain ) throws IOException Span.current() .setAttribute( "target.try." + tryCounter + ".status_code", resp.code() ); - logger.debug( "TRY({}/{}): Response missing or indicates server error: {}. Retrying", + logger.warn( "TRY({}/{}): Response missing or indicates server error: {}. Retrying", tryCounter, count, resp ); } } } catch( IOException e ) { - if ( tryCounter >= count ) - { - throw e; - } + latestException = e; Span.current().setAttribute( "target.try." + tryCounter + ".error_message", e.getMessage() ); Span.current() .setAttribute( "target.try." + tryCounter + ".error_class", e.getClass().getSimpleName() ); - logger.debug( "TRY(" + tryCounter + "/" + count + "): Failed upstream request: " + req.url(), e ); + logger.warn( "TRY(" + tryCounter + "/" + count + "): Failed upstream request: " + req.url(), e ); } try @@ -447,7 +445,9 @@ public Response intercept( @NotNull Chain chain ) throws IOException Span.current().setAttribute( "target.retries", tryCounter ); - throw new IOException( "Proxy retry interceptor reached an unexpected fall-through condition!" ); + throw new IOException( String.format( + "Proxy retry interceptor reached an unexpected fall-through condition! %s, Failed upstream request: %s", + latestException, req.url() ) ); } }