#pragma once #include #include #include #include #include namespace NYT::NDetail { //////////////////////////////////////////////////////////////////////////////// TErrorResponse ToErrorResponse(TErrorException ex); //////////////////////////////////////////////////////////////////////////////// template ::NThreading::TFuture WrapRpcError(::NThreading::TFuture future) { return future.Apply(([](auto&& tryResult){ try { tryResult.TryRethrow(); return std::forward(tryResult); } catch (TErrorException ex) { return ::NThreading::MakeErrorFuture(std::make_exception_ptr(ToErrorResponse(std::move(ex)))); } })); } template TResult WaitAndProcess(TFuture future) { try { if constexpr (std::is_same_v) { NConcurrency::WaitFor(future).ThrowOnError(); } else { auto result = NConcurrency::WaitFor(future).ValueOrThrow(); return result; } } catch (TErrorException ex) { throw ToErrorResponse(std::move(ex)); } } //////////////////////////////////////////////////////////////////////////////// } // namespace NYT::NDetail