Skip to content

Commit caf04bd

Browse files
authored
Merge pull request #1503 from mNantern/master
Fixes #1478 : allow cleaner error propagation
2 parents c1d4bb6 + 82a6610 commit caf04bd

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

hystrix-core/src/main/java/com/netflix/hystrix/AbstractCommand.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,9 +1561,15 @@ protected Throwable decomposeException(Exception e) {
15611561
return (IllegalStateException) e;
15621562
}
15631563
if (e instanceof HystrixBadRequestException) {
1564+
if (shouldNotBeWrapped(e.getCause())) {
1565+
return e.getCause();
1566+
}
15641567
return (HystrixBadRequestException) e;
15651568
}
15661569
if (e.getCause() instanceof HystrixBadRequestException) {
1570+
if(shouldNotBeWrapped(e.getCause().getCause())) {
1571+
return e.getCause().getCause();
1572+
}
15671573
return (HystrixBadRequestException) e.getCause();
15681574
}
15691575
if (e instanceof HystrixRuntimeException) {

hystrix-core/src/test/java/com/netflix/hystrix/AbstractTestHystrixCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
public interface AbstractTestHystrixCommand<R> extends HystrixObservable<R>, InspectableBuilder {
2121

2222
enum ExecutionResult {
23-
SUCCESS, FAILURE, ASYNC_FAILURE, HYSTRIX_FAILURE, NOT_WRAPPED_FAILURE, ASYNC_HYSTRIX_FAILURE, RECOVERABLE_ERROR, ASYNC_RECOVERABLE_ERROR, UNRECOVERABLE_ERROR, ASYNC_UNRECOVERABLE_ERROR, BAD_REQUEST, ASYNC_BAD_REQUEST, MULTIPLE_EMITS_THEN_SUCCESS, MULTIPLE_EMITS_THEN_FAILURE, NO_EMITS_THEN_SUCCESS
23+
SUCCESS, FAILURE, ASYNC_FAILURE, HYSTRIX_FAILURE, NOT_WRAPPED_FAILURE, ASYNC_HYSTRIX_FAILURE, RECOVERABLE_ERROR, ASYNC_RECOVERABLE_ERROR, UNRECOVERABLE_ERROR, ASYNC_UNRECOVERABLE_ERROR, BAD_REQUEST, ASYNC_BAD_REQUEST, BAD_REQUEST_NOT_WRAPPED, MULTIPLE_EMITS_THEN_SUCCESS, MULTIPLE_EMITS_THEN_FAILURE, NO_EMITS_THEN_SUCCESS
2424
}
2525

2626
enum FallbackResult {

hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,33 @@ public void testNotWrappedExceptionWithNoFallback() {
197197
assertSaneHystrixRequestLog(1);
198198
}
199199

200+
/**
201+
* Test a command execution that throws an exception that should not be wrapped.
202+
*/
203+
@Test
204+
public void testNotWrappedBadRequestWithNoFallback() {
205+
TestHystrixCommand<Integer> command = getCommand(ExecutionIsolationStrategy.THREAD, AbstractTestHystrixCommand.ExecutionResult.BAD_REQUEST_NOT_WRAPPED, AbstractTestHystrixCommand.FallbackResult.UNIMPLEMENTED);
206+
try {
207+
command.execute();
208+
fail("we shouldn't get here");
209+
} catch (HystrixRuntimeException e) {
210+
e.printStackTrace();
211+
fail("we shouldn't get a HystrixRuntimeException");
212+
} catch (RuntimeException e) {
213+
assertTrue(e instanceof NotWrappedByHystrixTestRuntimeException);
214+
}
215+
216+
assertTrue(command.getExecutionTimeInMilliseconds() > -1);
217+
assertTrue(command.getEventCounts().contains(HystrixEventType.BAD_REQUEST));
218+
assertCommandExecutionEvents(command, HystrixEventType.BAD_REQUEST);
219+
assertNotNull(command.getExecutionException());
220+
assertTrue(command.getExecutionException() instanceof HystrixBadRequestException);
221+
assertTrue(command.getExecutionException().getCause() instanceof NotWrappedByHystrixTestRuntimeException);
222+
assertEquals(0, command.getBuilder().metrics.getCurrentConcurrentExecutionCount());
223+
assertSaneHystrixRequestLog(1);
224+
}
225+
226+
200227
/**
201228
* Test a command execution that fails but has a fallback.
202229
*/
@@ -4908,6 +4935,8 @@ protected Integer run() throws Exception {
49084935
throw new StackOverflowError("Unrecoverable Error for TestHystrixCommand");
49094936
} else if (executionResult == AbstractTestHystrixCommand.ExecutionResult.BAD_REQUEST) {
49104937
throw new HystrixBadRequestException("Execution BadRequestException for TestHystrixCommand");
4938+
} else if (executionResult == AbstractTestHystrixCommand.ExecutionResult.BAD_REQUEST_NOT_WRAPPED) {
4939+
throw new HystrixBadRequestException("Execution BadRequestException for TestHystrixCommand", new NotWrappedByHystrixTestRuntimeException());
49114940
} else {
49124941
throw new RuntimeException("You passed in a executionResult enum that can't be represented in HystrixCommand: " + executionResult);
49134942
}

0 commit comments

Comments
 (0)