From f544317320a45b42eb436fd1d88bc9aa1c62d1b9 Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Tue, 23 Jul 2024 15:40:20 +1000 Subject: [PATCH] simplify LogErrorHandler --- .../http/handlers/LogErrorHandler.java | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/tech/pegasys/web3signer/core/service/http/handlers/LogErrorHandler.java b/core/src/main/java/tech/pegasys/web3signer/core/service/http/handlers/LogErrorHandler.java index b72ec65af..1130b7b9f 100644 --- a/core/src/main/java/tech/pegasys/web3signer/core/service/http/handlers/LogErrorHandler.java +++ b/core/src/main/java/tech/pegasys/web3signer/core/service/http/handlers/LogErrorHandler.java @@ -27,19 +27,7 @@ public class LogErrorHandler implements Handler { @Override public void handle(final RoutingContext failureContext) { if (failureContext.failed()) { - final String requestUri = - getRequestUri(failureContext) - .orElse("Vertx failed to calculate request URI due to malformed host header."); - - if (failureContext.failure() != null) { - LOG.error( - "Failed request: {} due to {}", - requestUri, - failureContext.failure().getMessage(), - failureContext.failure()); - } else { - LOG.error("Failed request: {}", requestUri); - } + LOG.error("Failed request: {}", getRequestUri(failureContext), failureContext.failure()); // Let the next matching route or error handler deal with the error, we only handle logging failureContext.next(); @@ -48,12 +36,13 @@ public void handle(final RoutingContext failureContext) { } } - private static Optional getRequestUri(final RoutingContext failureContext) { + private static String getRequestUri(final RoutingContext failureContext) { try { - return Optional.ofNullable(failureContext.request().absoluteURI()); + return Optional.ofNullable(failureContext.request().absoluteURI()).orElse("[null uri]"); } catch (final NullPointerException e) { // absoluteURI() can throw NPE when header host is malformed. - return Optional.empty(); + LOG.warn("Vertx failed to calculate request URI due to malformed host header."); + return "[null uri]"; } } }