Skip to content

Commit

Permalink
iss1545: don't get cause from HystrixBadRequestException if command t…
Browse files Browse the repository at this point in the history
…hrows HystrixBadRequestException without cause
  • Loading branch information
dmgcodevil committed May 9, 2017
1 parent fefdc37 commit 70e832f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit 70e832f

Please sign in to comment.