summaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/rpc_client/wrap_rpc_error.cpp
blob: d95687c085884904c3fd6be4c98a366a7c9ba5fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "wrap_rpc_error.h"

#include <library/cpp/yson/node/node.h>

namespace NYT::NDetail {

////////////////////////////////////////////////////////////////////////////////

TYtError ToYtError(const TError& err)
{
    TNode::TMapType attributes;
    for (const auto& [key, value] : err.Attributes().ListPairs()) {
        attributes.emplace(key, value);
    }

    const auto& innerErrors = err.InnerErrors();

    TVector<TYtError> errors;
    errors.reserve(innerErrors.size());
    for (const auto& inner : innerErrors) {
        errors.push_back(ToYtError(inner));
    }
    return {err.GetCode(), TString(err.GetMessage()), std::move(errors), std::move(attributes)};
}

TErrorResponse ToErrorResponse(TErrorException ex)
{
    auto error = std::move(ex.Error());
    const auto ytError = ToYtError(error);
    const auto requestId = error.Attributes().Find<TString>("request_id").value_or("0-0-0-0");
    throw TErrorResponse(std::move(ytError), requestId);
}

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT::NDetail