diff options
author | Alexey Efimov <xeno@prnwatch.com> | 2022-06-06 16:47:13 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-06-06 16:47:13 +0300 |
commit | 53ff143b6db6dffa52da9b82f7e62e17d68ee1e7 (patch) | |
tree | 12915574947c765ef82b0f4830a83d6ad90d0ade | |
parent | 935d02f1a6e32dbadfa5f1a56304260a23aa7d7f (diff) | |
download | ydb-53ff143b6db6dffa52da9b82f7e62e17d68ee1e7.tar.gz |
PR from branch users/xenoxeno/merge-KIKIMR-14997
change format of error field KIKIMR-14997
REVIEW: 2610351
fix error information in query handler KIKIMR-14997
REVIEW: 2601494
REVIEW: 2613435
x-ydb-stable-ref: e52ba2752ca5413441f96eb1432368303fa4eb7e
-rw-r--r-- | ydb/core/viewer/json_query.h | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/ydb/core/viewer/json_query.h b/ydb/core/viewer/json_query.h index 4926a8c6c1..6e1e7eb3a0 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,24 @@ 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() << ' '; - } - err << queryIssue.message(); + NJson::TJsonValue& issue = jsonIssues.AppendValue({}); + NProtobufJson::Proto2Json(queryIssue, issue); } - out << err; - - out << "\r\n"; + // find first deepest error + 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) { + const Ydb::Issue::IssueMessage& issue = (*protoIssues)[0]; + NProtobufJson::Proto2Json(issue, response["error"]); + } + out << NJson::WriteJson(response, false); } ReplyAndDie(out, ctx); |