From 1592af7e1b97424ac41e8d2102dccfc7d6caee6d Mon Sep 17 00:00:00 2001 From: sfi2022 <109145215+sfi2022@users.noreply.github.com> Date: Thu, 18 Jul 2024 12:44:20 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=F0=9F=90=9B=20Refactoring,?= =?UTF-8?q?=20exception=20logging=20added.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../muenchen/mobidam/s3/S3RouteBuilder.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/muenchen/mobidam/s3/S3RouteBuilder.java b/src/main/java/de/muenchen/mobidam/s3/S3RouteBuilder.java index 5199db0..5ba83c3 100644 --- a/src/main/java/de/muenchen/mobidam/s3/S3RouteBuilder.java +++ b/src/main/java/de/muenchen/mobidam/s3/S3RouteBuilder.java @@ -34,7 +34,7 @@ public void configure() { .handled(true) .process(exchange -> { var s3Exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, S3Exception.class); - logException(exchange, s3Exception); + logException(exchange, s3Exception.getMessage()); exchange.getMessage().setBody(ErrorResponseBuilder.build(s3Exception.statusCode(), s3Exception.getClass().getName())); }); @@ -42,7 +42,7 @@ public void configure() { .handled(true) .process(exchange -> { var s3Exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, ResolveEndpointFailedException.class); - logException(exchange, s3Exception); + logException(exchange, s3Exception.getMessage()); exchange.getMessage().setBody(ErrorResponseBuilder.build(400, s3Exception.getClass().getName())); }); @@ -52,15 +52,11 @@ public void configure() { if (exchange.getMessage().getBody()instanceof ErrorResponse res) { exchange.getMessage().setHeader(Exchange.HTTP_RESPONSE_CODE, res.getStatus()); if (exchange.getIn().getHeader(Constants.CAMEL_SERVLET_CONTEXT_PATH).equals(Constants.ARCHIVE_ENTITY)) { - log.error( - String.format("Archive clean up (%s): %s", exchange.getProperty(Constants.ARCHIVE_ENTITY, MobidamArchive.class).toString(), - res.getError())); - } else { - log.error(exchange.getIn().getBody().toString()); + logException(exchange, res.getError()); } } else { Throwable exception = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class); - logException(exchange, exception); + logException(exchange, exception.getMessage()); ErrorResponse res = ErrorResponseBuilder.build(HttpStatus.INTERNAL_SERVER_ERROR.value(), exception.getClass().getName()); exchange.getMessage().setBody(res); } @@ -127,12 +123,13 @@ public void configure() { } - private void logException(Exchange exchange, Throwable exception) { + private void logException(Exchange exchange, String errorMessage) { if (exchange.getIn().getHeader(Constants.CAMEL_SERVLET_CONTEXT_PATH).equals(Constants.ARCHIVE_ENTITY)) { - log.error(String.format("Archive clean up (%s)", exchange.getProperty(Constants.ARCHIVE_ENTITY, MobidamArchive.class).toString()), - exception); + log.error(String.format("Archive clean up (%s): %s", exchange.getProperty(Constants.ARCHIVE_ENTITY, MobidamArchive.class).toString(), errorMessage)); } else { - log.error("Error occurred in route", exception); + log.error("Error occurred in route with message '{}'.", errorMessage); } } + + }