diff options
author | Alexey Efimov <xeno@prnwatch.com> | 2022-06-01 22:29:19 +0300 |
---|---|---|
committer | Alexey Efimov <xeno@prnwatch.com> | 2022-06-01 22:29:19 +0300 |
commit | 1dd048220847dc0b613de06692ba9e98a9a96d65 (patch) | |
tree | a44fabcfb24ea45643de296ec4a4ac05c452696d | |
parent | e8fac0102c6dbd874df5ca1799b131090a7da527 (diff) | |
download | ydb-1dd048220847dc0b613de06692ba9e98a9a96d65.tar.gz |
fix error information in query handler KIKIMR-14997
ref:89b95dfeb016e11f42488dcbd5bc9be46c2528bc
-rw-r--r-- | ydb/core/viewer/json_query.h | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/ydb/core/viewer/json_query.h b/ydb/core/viewer/json_query.h index 4926a8c6c1..315b798aa7 100644 --- a/ydb/core/viewer/json_query.h +++ b/ydb/core/viewer/json_query.h @@ -6,6 +6,7 @@ #include <library/cpp/actors/core/mon.h> #include <library/cpp/json/json_value.h> #include <library/cpp/json/json_reader.h> +#include <library/cpp/protobuf/json/proto2json.h> #include <ydb/core/node_whiteboard/node_whiteboard.h> #include <ydb/core/kqp/kqp.h> #include <ydb/core/kqp/executer/kqp_executer.h> @@ -269,21 +270,28 @@ private: out << json.Str() << "}"; } } else { - out << "HTTP/1.1 400 Bad Request\r\nContent-Type: text/plain\r\nConnection: Close\r\n\r\n"; + out << "HTTP/1.1 400 Bad Request\r\nContent-Type: application/json\r\nConnection: Close\r\n\r\n"; + NJson::TJsonValue response; + NJson::TJsonValue& jsonIssues = response["issues"]; - TStringBuilder err; for (const auto& queryIssue : record.GetResponse().GetQueryIssues()) { - if (!err.empty()) { - err << '\n'; - } - if (queryIssue.has_position()) { - err << queryIssue.position().row() << ':' << queryIssue.position().column() << ' '; + NJson::TJsonValue& issue = jsonIssues.AppendValue({}); + NProtobufJson::Proto2Json(queryIssue, issue); + } + const google::protobuf::RepeatedPtrField<Ydb::Issue::IssueMessage>* protoIssues = &(record.GetResponse().GetQueryIssues()); + while (protoIssues->size() > 0 && (*protoIssues)[0].issuesSize() > 0) { + protoIssues = &((*protoIssues)[0].issues()); + } + if (protoIssues->size() > 0) { + TStringBuilder err; + const Ydb::Issue::IssueMessage& issue = (*protoIssues)[0]; + if (issue.has_position()) { + err << issue.position().row() << ':' << issue.position().column() << ' '; } - err << queryIssue.message(); + err << issue.message(); + response["error"] = err; } - out << err; - - out << "\r\n"; + out << NJson::WriteJson(response, false); } ReplyAndDie(out, ctx); |