Skip to content

Commit

Permalink
Fix #1107: log unmapped exceptions in addition to mapping (#1112)
Browse files Browse the repository at this point in the history
  • Loading branch information
tatu-at-datastax authored May 22, 2024
1 parent 9729ac8 commit f3af0d0
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Throwable, String, CommandResult.Error> MAPPER_WITH_MESSAGE =
(throwable, message) -> {
// if our own exception, shortcut
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f3af0d0

Please sign in to comment.