Skip to content

Commit b8ac60a

Browse files
author
hiddenpath
committed
YT-23616: Remove HttpCode from TErrorResponse
commit_hash:412a7a1e02eb68d388aff73a439e98f6f2dab8a6
1 parent 75f5993 commit b8ac60a

File tree

6 files changed

+28
-53
lines changed

6 files changed

+28
-53
lines changed

yt/cpp/mapreduce/client/transaction_pinger.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,23 @@ namespace {
4040

4141
void CheckError(const TString& requestId, NHttp::IResponsePtr response)
4242
{
43-
TErrorResponse errorResponse(static_cast<int>(response->GetStatusCode()), requestId);
44-
4543
if (const auto* ytError = response->GetHeaders()->Find("X-YT-Error")) {
46-
errorResponse.ParseFromJsonError(*ytError);
47-
}
48-
if (errorResponse.IsOk()) {
49-
return;
50-
}
44+
TYtError error;
45+
error.ParseFrom(*ytError);
5146

52-
YT_LOG_ERROR("RSP %v - HTTP %v - %v",
47+
TErrorResponse errorResponse(std::move(error), requestId);
48+
if (errorResponse.IsOk()) {
49+
return;
50+
}
51+
52+
YT_LOG_ERROR("RSP %v - HTTP %v - %v",
5353
requestId,
5454
response->GetStatusCode(),
5555
errorResponse.AsStrBuf());
5656

57-
ythrow errorResponse;
58-
59-
////////////////////////////////////////////////////////////////////////////////
60-
61-
} // namespace
57+
ythrow errorResponse;
58+
}
59+
}
6260

6361
void PingTx(NHttp::IClientPtr httpClient, const TPingableTransaction& tx)
6462
{

yt/cpp/mapreduce/http/http.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -766,14 +766,12 @@ THttpResponse::THttpResponse(
766766
return;
767767
}
768768

769-
ErrorResponse_ = TErrorResponse(HttpCode_, Context_.RequestId);
770-
771769
auto logAndSetError = [&] (int code, const TString& rawError) {
772770
YT_LOG_ERROR("RSP %v - HTTP %v - %v",
773771
Context_.RequestId,
774772
HttpCode_,
775773
rawError.data());
776-
ErrorResponse_->SetError(TYtError(code, rawError));
774+
ErrorResponse_ = TErrorResponse(TYtError(code, rawError), Context_.RequestId);
777775
};
778776

779777
switch (HttpCode_) {
@@ -807,8 +805,7 @@ THttpResponse::THttpResponse(
807805
ExtendGenericError(*ErrorResponse_, NClusterErrorCodes::NBus::TransportError, "transport error");
808806
}
809807
} else {
810-
ErrorResponse_->SetRawError(
811-
errorString + " - X-YT-Error is missing in headers");
808+
ErrorResponse_ = TErrorResponse(TYtError(errorString + " - X-YT-Error is missing in headers"), Context_.RequestId);
812809
}
813810
break;
814811
}
@@ -854,8 +851,9 @@ TMaybe<TErrorResponse> THttpResponse::ParseError(const THttpHeaders& headers)
854851
{
855852
for (const auto& header : headers) {
856853
if (header.Name() == "X-YT-Error") {
857-
TErrorResponse errorResponse(HttpCode_, Context_.RequestId);
858-
errorResponse.ParseFromJsonError(header.Value());
854+
TYtError error;
855+
error.ParseFrom(header.Value());
856+
TErrorResponse errorResponse(std::move(error), Context_.RequestId);
859857
if (errorResponse.IsOk()) {
860858
return Nothing();
861859
}

yt/cpp/mapreduce/http/http_client.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,21 @@ TMaybe<TErrorResponse> GetErrorResponse(const TString& hostName, const TString&
4141
return {};
4242
}
4343

44-
TErrorResponse errorResponse(static_cast<int>(httpCode), requestId);
45-
4644
auto logAndSetError = [&] (int code, const TString& rawError) {
4745
YT_LOG_ERROR("RSP %v - HTTP %v - %v",
4846
requestId,
4947
httpCode,
5048
rawError.data());
51-
errorResponse.SetError(TYtError(code, rawError));
49+
return TErrorResponse(TYtError(code, rawError), requestId);
5250
};
5351

5452

5553
switch (httpCode) {
5654
case NHttp::EStatusCode::TooManyRequests:
57-
logAndSetError(NClusterErrorCodes::NSecurityClient::RequestQueueSizeLimitExceeded, "request rate limit exceeded");
58-
break;
55+
return logAndSetError(NClusterErrorCodes::NSecurityClient::RequestQueueSizeLimitExceeded, "request rate limit exceeded");
5956

6057
case NHttp::EStatusCode::InternalServerError:
61-
logAndSetError(NClusterErrorCodes::NRpc::Unavailable, "internal error in proxy " + hostName);
62-
break;
58+
return logAndSetError(NClusterErrorCodes::NRpc::Unavailable, "internal error in proxy " + hostName);
6359

6460
default: {
6561
TStringStream httpHeaders;
@@ -78,7 +74,10 @@ TMaybe<TErrorResponse> GetErrorResponse(const TString& hostName, const TString&
7874
errorString.data());
7975

8076
if (auto errorHeader = response->GetHeaders()->Find("X-YT-Error")) {
81-
errorResponse.ParseFromJsonError(*errorHeader);
77+
TYtError error;
78+
error.ParseFrom(*errorHeader);
79+
80+
TErrorResponse errorResponse(std::move(error), requestId);
8281
if (errorResponse.IsOk()) {
8382
return Nothing();
8483
}
@@ -88,13 +87,9 @@ TMaybe<TErrorResponse> GetErrorResponse(const TString& hostName, const TString&
8887
return errorResponse;
8988
}
9089

91-
errorResponse.SetRawError(
92-
errorString + " - X-YT-Error is missing in headers");
93-
break;
90+
return TErrorResponse(TYtError(errorString + " - X-YT-Error is missing in headers"), requestId);
9491
}
9592
}
96-
97-
return errorResponse;
9893
}
9994

10095
void CheckErrorResponse(const TString& hostName, const TString& requestId, const NHttp::IResponsePtr& response)
@@ -317,8 +312,9 @@ class TCoreHttpResponse
317312
TMaybe<TErrorResponse> ParseError(const NHttp::THeadersPtr& headers)
318313
{
319314
if (auto errorHeader = headers->Find("X-YT-Error")) {
320-
TErrorResponse errorResponse(static_cast<int>(Response_->GetStatusCode()), RequestId_);
321-
errorResponse.ParseFromJsonError(*errorHeader);
315+
TYtError error;
316+
error.ParseFrom(*errorHeader);
317+
TErrorResponse errorResponse(std::move(error), RequestId_);
322318
if (errorResponse.IsOk()) {
323319
return Nothing();
324320
}

yt/cpp/mapreduce/http_client/raw_batch_request.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,7 @@ void THttpRawBatchRequest::ParseResponse(
695695
if (errorIt == responseNode.end()) {
696696
BatchItemList_[i].ResponseParser->SetResponse(Nothing());
697697
} else {
698-
TErrorResponse error(400, requestId);
699-
error.SetError(TYtError(errorIt->second));
698+
TErrorResponse error(TYtError(errorIt->second), requestId);
700699
if (auto curInterval = IsRetriable(error) ? retryPolicy->OnRetriableError(error) : Nothing()) {
701700
YT_LOG_INFO(
702701
"Batch subrequest (%s) failed, will retry, error: %s",

yt/cpp/mapreduce/interface/errors.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,6 @@ TString TYtError::FullDescription() const
280280

281281
////////////////////////////////////////////////////////////////////////////////
282282

283-
TErrorResponse::TErrorResponse(int httpCode, const TString& requestId)
284-
: HttpCode_(httpCode)
285-
, RequestId_(requestId)
286-
{ }
287-
288283
TErrorResponse::TErrorResponse(TYtError error, const TString& requestId)
289284
: RequestId_(requestId)
290285
, Error_(std::move(error))
@@ -320,11 +315,6 @@ void TErrorResponse::SetIsFromTrailers(bool isFromTrailers)
320315
IsFromTrailers_ = isFromTrailers;
321316
}
322317

323-
int TErrorResponse::GetHttpCode() const
324-
{
325-
return HttpCode_;
326-
}
327-
328318
bool TErrorResponse::IsFromTrailers() const
329319
{
330320
return IsFromTrailers_;

yt/cpp/mapreduce/interface/errors.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ class TErrorResponse
157157
: public yexception
158158
{
159159
public:
160-
TErrorResponse(int httpCode, const TString& requestId);
161-
162160
TErrorResponse(TYtError error, const TString& requestId);
163161

164162
/// Get error object returned by server.
@@ -167,9 +165,6 @@ class TErrorResponse
167165
/// Get if (correlation-id) of request that was responded with error.
168166
TString GetRequestId() const;
169167

170-
/// Get HTTP code of response.
171-
int GetHttpCode() const;
172-
173168
/// Is error parsed from response trailers.
174169
bool IsFromTrailers() const;
175170

@@ -218,7 +213,6 @@ class TErrorResponse
218213
void Setup();
219214

220215
private:
221-
int HttpCode_;
222216
TString RequestId_;
223217
TYtError Error_;
224218
bool IsFromTrailers_ = false;

0 commit comments

Comments
 (0)