use of com.netflix.hystrix.contrib.javanica.exception.CommandActionExecutionException in project Hystrix by Netflix.
the class AbstractHystrixCommand method process.
/**
* Executes an action. If an action has failed and an exception is ignorable then propagate it as HystrixBadRequestException
* otherwise propagate original exception to trigger fallback method.
* Note: If an exception occurred in a command directly extends {@link java.lang.Throwable} then this exception cannot be re-thrown
* as original exception because HystrixCommand.run() allows throw subclasses of {@link java.lang.Exception}.
* Thus we need to wrap cause in RuntimeException, anyway in this case the fallback logic will be triggered.
*
* @param action the action
* @return result of command action execution
*/
Object process(Action action) throws Exception {
Object result;
try {
result = action.execute();
flushCache();
} catch (CommandActionExecutionException throwable) {
Throwable cause = throwable.getCause();
if (isIgnorable(cause)) {
throw new HystrixBadRequestException(cause.getMessage(), cause);
}
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} else if (cause instanceof Exception) {
throw (Exception) cause;
} else {
// instance of Throwable
throw new CommandActionExecutionException(cause);
}
}
return result;
}
use of com.netflix.hystrix.contrib.javanica.exception.CommandActionExecutionException in project Hystrix by Netflix.
the class GenericObservableCommand method resumeWithFallback.
/**
*{@inheritDoc}.
*/
@Override
protected Observable resumeWithFallback() {
if (commandActions.hasFallbackAction()) {
MetaHolder metaHolder = commandActions.getFallbackAction().getMetaHolder();
Throwable cause = getExecutionException();
if (cause instanceof CommandActionExecutionException) {
cause = cause.getCause();
}
Object[] args = createArgsForFallback(metaHolder, cause);
try {
Object res = commandActions.getFallbackAction().executeWithArgs(executionType, args);
if (res instanceof Observable) {
return (Observable) res;
} else if (res instanceof Single) {
return ((Single) res).toObservable();
} else if (res instanceof Completable) {
return ((Completable) res).toObservable();
} else {
return Observable.just(res);
}
} catch (Exception e) {
LOGGER.error(AbstractHystrixCommand.FallbackErrorMessageBuilder.create().append(commandActions.getFallbackAction(), e).build());
throw new FallbackInvocationException(e.getCause());
}
}
return super.resumeWithFallback();
}
use of com.netflix.hystrix.contrib.javanica.exception.CommandActionExecutionException in project Hystrix by Netflix.
the class GenericObservableCommand method construct.
/**
*{@inheritDoc}.
*/
@Override
protected Observable construct() {
Observable result;
try {
Observable observable = toObservable(commandActions.getCommandAction().execute(executionType));
result = observable.onErrorResumeNext(new Func1<Throwable, Observable>() {
@Override
public Observable call(Throwable throwable) {
if (isIgnorable(throwable)) {
return Observable.error(new HystrixBadRequestException(throwable.getMessage(), throwable));
}
return Observable.error(throwable);
}
});
flushCache();
} catch (CommandActionExecutionException throwable) {
Throwable cause = throwable.getCause();
if (isIgnorable(cause)) {
throw new HystrixBadRequestException(cause.getMessage(), cause);
}
throw throwable;
}
return result;
}
Aggregations