aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoruzhas <uzhas@ydb.tech>2023-02-02 18:37:37 +0300
committeruzhas <uzhas@ydb.tech>2023-02-02 18:37:37 +0300
commitb0cac7b0b9293a11a5f641f165fb6783fabc85f2 (patch)
tree1d8df0b3a296bf3a3a1d90679a40c416e2604ac9
parent41609726a5ae95273e9685748bd9d18e095495fe (diff)
downloadydb-b0cac7b0b9293a11a5f641f165fb6783fabc85f2.tar.gz
response 500 in case of reply error
-rw-r--r--ydb/core/public_http/fq_handlers.h15
-rw-r--r--ydb/core/public_http/http_req.cpp4
-rw-r--r--ydb/core/public_http/http_req.h1
3 files changed, 14 insertions, 6 deletions
diff --git a/ydb/core/public_http/fq_handlers.h b/ydb/core/public_http/fq_handlers.h
index aa89361d472..e1aba16c41d 100644
--- a/ydb/core/public_http/fq_handlers.h
+++ b/ydb/core/public_http/fq_handlers.h
@@ -367,12 +367,15 @@ public:
return;
}
- TStringStream json;
- auto* httpResult = google::protobuf::Arena::CreateMessage<THttpProtoResultType>(resp->GetArena());
- FqConvert(*grpcResult, *httpResult);
- FqPackToJson(json, *httpResult, jsonSettings);
-
- requestContext.ResponseOKJson(json.Str());
+ try {
+ TStringStream json;
+ auto* httpResult = google::protobuf::Arena::CreateMessage<THttpProtoResultType>(resp->GetArena());
+ FqConvert(*grpcResult, *httpResult);
+ FqPackToJson(json, *httpResult, jsonSettings);
+ requestContext.ResponseOKJson(json.Str());
+ } catch (const std::exception& e) {
+ requestContext.ResponseInternalServerError(TStringBuilder() << "Error during formatting response: " << e.what());
+ }
}
};
diff --git a/ydb/core/public_http/http_req.cpp b/ydb/core/public_http/http_req.cpp
index a491dfc22d3..f98eef0da4c 100644
--- a/ydb/core/public_http/http_req.cpp
+++ b/ydb/core/public_http/http_req.cpp
@@ -126,6 +126,10 @@ namespace NKikimr::NPublicHttp {
DoResponse("401", "Unauthorized", message);
}
+ void THttpRequestContext::ResponseInternalServerError(const TString& message) const {
+ DoResponse("500", "Internal Server Error", message);
+ }
+
void THttpRequestContext::DoResponse(TStringBuf status, TStringBuf message, TStringBuf body, TStringBuf contentType) const {
auto res = Request->CreateResponse(status, message, contentType, body);
ActorSystem->Send(Sender, new NHttp::TEvHttpProxy::TEvHttpOutgoingResponse(res));
diff --git a/ydb/core/public_http/http_req.h b/ydb/core/public_http/http_req.h
index 27c688fc762..478ae59f92a 100644
--- a/ydb/core/public_http/http_req.h
+++ b/ydb/core/public_http/http_req.h
@@ -22,6 +22,7 @@ public:
void ResponseNotFound() const;
void ResponseNoContent() const;
void ResponseUnauthenticated(const TString& message) const;
+ void ResponseInternalServerError(const TString& message) const;
void SetPathParams(std::map<TString, TString> pathParams);
const std::map<TString, TString>& GetPathParams() const;