@Override public boolean isError() { return result.isError(); }
/** * Returns the value if this is a success result, or throws the exception if it's an error. * * @return the value (if this is a success result) * @throws Exception the error (if this is an error result) */ default T getValueOrThrow() throws Exception { if (isError()) { throw Exceptions.toException(getThrowable()); } else { return getValue(); } }
default Operation wiretap(Action<? super Optional<? extends Throwable>> action) { return promise().wiretap(r -> { if (r.isError()) { action.execute(Optional.of(r.getThrowable())); } else { action.execute(Optional.<Throwable>empty()); } } ).operation(); }
/** * Signals this downstream, based on the given result. * * @param result the result to signal */ default void accept(Result<? extends T> result) { if (result.isError()) { error(result.getThrowable()); } else { success(result.getValue()); } }
private <T extends HttpResponse> Promise<T> intercept(Promise<T> promise, Action<? super HttpResponse> action, Action<? super Throwable> errorAction) { return promise.wiretap(r -> { if (r.isError()) { ExecController.require() .fork() .eventLoop(Execution.current().getEventLoop()) .start(e -> errorAction.execute(r.getThrowable()) ); } }) .next(r -> ExecController.require() .fork() .eventLoop(Execution.current().getEventLoop()) .start(e -> action.execute(r) ) ); }