Search in sources :

Example 1 with FallbackInvocationException

use of com.netflix.hystrix.contrib.javanica.exception.FallbackInvocationException in project Hystrix by Netflix.

the class BatchHystrixCommand method getFallback.

@Override
@SuppressWarnings("unchecked")
protected List<Object> getFallback() {
    if (getFallbackAction() != null) {
        final CommandAction commandAction = getFallbackAction();
        try {
            return (List<Object>) process(new Action() {

                @Override
                Object execute() {
                    MetaHolder metaHolder = commandAction.getMetaHolder();
                    Object[] args = toArgs(getCollapsedRequests());
                    args = createArgsForFallback(args, metaHolder, getExecutionException());
                    return commandAction.executeWithArgs(commandAction.getMetaHolder().getFallbackExecutionType(), args);
                }
            });
        } catch (Throwable e) {
            LOGGER.error(FallbackErrorMessageBuilder.create().append(commandAction, e).build());
            throw new FallbackInvocationException(unwrapCause(e));
        }
    } else {
        return super.getFallback();
    }
}
Also used : FallbackInvocationException(com.netflix.hystrix.contrib.javanica.exception.FallbackInvocationException) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with FallbackInvocationException

use of com.netflix.hystrix.contrib.javanica.exception.FallbackInvocationException 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 {
                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();
}
Also used : CommandActionExecutionException(com.netflix.hystrix.contrib.javanica.exception.CommandActionExecutionException) FallbackInvocationException(com.netflix.hystrix.contrib.javanica.exception.FallbackInvocationException) Observable(rx.Observable) CommandActionExecutionException(com.netflix.hystrix.contrib.javanica.exception.CommandActionExecutionException) FallbackInvocationException(com.netflix.hystrix.contrib.javanica.exception.FallbackInvocationException) HystrixBadRequestException(com.netflix.hystrix.exception.HystrixBadRequestException)

Aggregations

FallbackInvocationException (com.netflix.hystrix.contrib.javanica.exception.FallbackInvocationException)2 CommandActionExecutionException (com.netflix.hystrix.contrib.javanica.exception.CommandActionExecutionException)1 HystrixBadRequestException (com.netflix.hystrix.exception.HystrixBadRequestException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Observable (rx.Observable)1