diff --git a/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/aop/aspectj/HystrixCommandAspect.java b/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/aop/aspectj/HystrixCommandAspect.java index b36d12326..6b5c3b3e8 100644 --- a/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/aop/aspectj/HystrixCommandAspect.java +++ b/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/aop/aspectj/HystrixCommandAspect.java @@ -103,7 +103,7 @@ public Object methodsAnnotatedWithHystrixCommand(final ProceedingJoinPoint joinP result = executeObservable(invokable, executionType, metaHolder); } } catch (HystrixBadRequestException e) { - throw e.getCause(); + throw e.getCause() != null ? e.getCause() : e; } catch (HystrixRuntimeException e) { throw hystrixRuntimeExceptionToThrowable(metaHolder, e); } diff --git a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/fallback/BasicCommandFallbackTest.java b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/fallback/BasicCommandFallbackTest.java index 99153fd3e..4fd270882 100644 --- a/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/fallback/BasicCommandFallbackTest.java +++ b/hystrix-contrib/hystrix-javanica/src/test/java/com/netflix/hystrix/contrib/javanica/test/common/fallback/BasicCommandFallbackTest.java @@ -26,6 +26,7 @@ import com.netflix.hystrix.contrib.javanica.test.common.BasicHystrixTest; import com.netflix.hystrix.contrib.javanica.test.common.domain.Domain; import com.netflix.hystrix.contrib.javanica.test.common.domain.User; +import com.netflix.hystrix.exception.HystrixBadRequestException; import org.apache.commons.lang3.Validate; import org.junit.Before; import org.junit.Test; @@ -36,6 +37,7 @@ import static com.netflix.hystrix.contrib.javanica.test.common.CommonUtils.getHystrixCommandByKey; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; public abstract class BasicCommandFallbackTest extends BasicHystrixTest { @@ -206,6 +208,16 @@ public void testCommandWithFallbackWithAdditionalParameter() { assertEquals("def", user.getName()); } + @Test(expected = HystrixBadRequestException.class) + public void testCommandThrowsHystrixBadRequestExceptionWithNoCause() { + try { + userService.commandThrowsHystrixBadRequestExceptionWithNoCause(null, null); + } finally { + HystrixInvokableInfo asyncCommandWithAsyncFallbackCommand = getHystrixCommandByKey("commandThrowsHystrixBadRequestExceptionWithNoCause"); + assertFalse(asyncCommandWithAsyncFallbackCommand.getExecutionEvents().contains(HystrixEventType.FALLBACK_SUCCESS)); + } + } + public static class UserService { @HystrixCommand(fallbackMethod = "fallback") @@ -399,6 +411,11 @@ public User commandWithFallbackReturnSuperType(final String id, final String nam return new User(id, name); } + @HystrixCommand(fallbackMethod = "staticFallback") + public User commandThrowsHystrixBadRequestExceptionWithNoCause(final String id, final String name){ + throw new HystrixBadRequestException("invalid arguments"); + } + private User fallbackReturnSubTypeOfDomain(final String id, final String name) { return new User("def", "def"); }