get rid of class cast exception and add a new testcase for that issue (#11951)

This commit is contained in:
TSFenwick 2021-11-22 08:44:20 -08:00 committed by GitHub
parent 0a9a908031
commit a4cb1de87a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -78,7 +78,7 @@ class ErrorHandler
return new RuntimeException(errorResponseTransformStrategy.transformIfNeeded((SanitizableException) error.getCause()));
}
QueryInterruptedException wrappedError = QueryInterruptedException.wrapIfNeeded(error);
return (QueryInterruptedException) errorResponseTransformStrategy.transformIfNeeded(wrappedError);
return (QueryException) errorResponseTransformStrategy.transformIfNeeded(wrappedError);
}
/**

View File

@ -78,4 +78,20 @@ public class ErrorHandlerTest
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());
}
}