Skip to content

Commit

Permalink
get rid of class cast exception and add a new testcase for that issue (
Browse files Browse the repository at this point in the history
  • Loading branch information
TSFenwick authored Nov 22, 2021
1 parent 0a9a908 commit a4cb1de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public <T extends Throwable> RuntimeException sanitize(T error)
return new RuntimeException(errorResponseTransformStrategy.transformIfNeeded((SanitizableException) error.getCause()));
}
QueryInterruptedException wrappedError = QueryInterruptedException.wrapIfNeeded(error);
return (QueryInterruptedException) errorResponseTransformStrategy.transformIfNeeded(wrappedError);
return (QueryException) errorResponseTransformStrategy.transformIfNeeded(wrappedError);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,20 @@ public void testErrorHandlerHasAffectingErrorResponseTransformStrategyReturnsFal
ErrorHandler errorHandler = new ErrorHandler(serverConfig);
Assert.assertFalse(errorHandler.hasAffectingErrorResponseTransformStrategy());
}

@Test
public void testErrorHandlerHandlesNonSanitizableExceptionCorrectly()
{
ServerConfig serverConfig = Mockito.mock(ServerConfig.class);
AllowedRegexErrorResponseTransformStrategy emptyAllowedRegexErrorResponseTransformStrategy = new AllowedRegexErrorResponseTransformStrategy(
ImmutableList.of());

Mockito.when(serverConfig.getErrorResponseTransformStrategy())
.thenReturn(emptyAllowedRegexErrorResponseTransformStrategy);
ErrorHandler errorHandler = new ErrorHandler(serverConfig);

Exception input = new Exception("message");
RuntimeException output = errorHandler.sanitize(input);
Assert.assertEquals(null, output.getMessage());
}
}

0 comments on commit a4cb1de

Please sign in to comment.