From 21d95aaafae8807bbef6aa28bb9e449f89f165ce Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Wed, 22 May 2024 11:50:48 -0700 Subject: [PATCH] Fix #1107: log unmapped exceptions in addition to mapping --- .../exception/mappers/ThrowableToErrorMapper.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/io/stargate/sgv2/jsonapi/exception/mappers/ThrowableToErrorMapper.java b/src/main/java/io/stargate/sgv2/jsonapi/exception/mappers/ThrowableToErrorMapper.java index da8cacf984..f840fa4827 100644 --- a/src/main/java/io/stargate/sgv2/jsonapi/exception/mappers/ThrowableToErrorMapper.java +++ b/src/main/java/io/stargate/sgv2/jsonapi/exception/mappers/ThrowableToErrorMapper.java @@ -17,12 +17,16 @@ import java.util.Map; import java.util.function.BiFunction; import java.util.function.Function; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Simple mapper for mapping {@link Throwable}s to {@link CommandResult.Error}, with a default * implementation. */ public final class ThrowableToErrorMapper { + private static final Logger logger = LoggerFactory.getLogger(ThrowableToErrorMapper.class); + private static final BiFunction MAPPER_WITH_MESSAGE = (throwable, message) -> { // if our own exception, shortcut @@ -46,6 +50,10 @@ public final class ThrowableToErrorMapper { } // handle all other exceptions + logger.error( + String.format( + "Unrecognized exception caught, mapped to SERVER_UNHANDLED_ERROR: %s", message), + throwable); return ErrorCode.SERVER_UNHANDLED_ERROR .toApiException("root cause: (%s) %s", throwable.getClass().getName(), message) .getCommandResultError(Response.Status.INTERNAL_SERVER_ERROR); @@ -166,6 +174,10 @@ private static CommandResult.Error handleAllNodesFailedException( } } // should not happen + logger.error( + String.format( + "Unrecognized exception caught, mapped to SERVER_UNHANDLED_ERROR: %s", message), + throwable); return ErrorCode.SERVER_UNHANDLED_ERROR .toApiException("root cause: (%s) %s", throwable.getClass().getName(), message) .getCommandResultError(Response.Status.INTERNAL_SERVER_ERROR);