mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 10:25:47 +02:00
fix: correct json response for errors (#2813)
Fixes #2811 Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
parent
b2e2ad6e04
commit
d3b90c8210
2 changed files with 27 additions and 3 deletions
|
@ -124,7 +124,7 @@ struct CaptureVisitor {
|
|||
}
|
||||
|
||||
void operator()(CapturingReplyBuilder::Error err) {
|
||||
str = absl::StrCat(R"({"error": ")", err.first);
|
||||
str = absl::StrCat(R"({"error": ")", err.first, "\"");
|
||||
}
|
||||
|
||||
void operator()(facade::OpStatus status) {
|
||||
|
@ -132,7 +132,13 @@ struct CaptureVisitor {
|
|||
}
|
||||
|
||||
void operator()(const CapturingReplyBuilder::StrArrPayload& sa) {
|
||||
absl::StrAppend(&str, "not_implemented");
|
||||
absl::StrAppend(&str, "[");
|
||||
for (const auto& val : sa.arr) {
|
||||
absl::StrAppend(&str, JsonEscape(val), ",");
|
||||
}
|
||||
if (sa.arr.size())
|
||||
str.pop_back();
|
||||
absl::StrAppend(&str, "]");
|
||||
}
|
||||
|
||||
void operator()(unique_ptr<CapturingReplyBuilder::CollectionPayload> cp) {
|
||||
|
@ -152,7 +158,18 @@ struct CaptureVisitor {
|
|||
}
|
||||
|
||||
void operator()(facade::SinkReplyBuilder::MGetResponse resp) {
|
||||
absl::StrAppend(&str, "not_implemented");
|
||||
absl::StrAppend(&str, "[");
|
||||
for (const auto& val : resp.resp_arr) {
|
||||
if (val) {
|
||||
absl::StrAppend(&str, JsonEscape(val->value), ",");
|
||||
} else {
|
||||
absl::StrAppend(&str, "null,");
|
||||
}
|
||||
}
|
||||
|
||||
if (resp.resp_arr.size())
|
||||
str.pop_back();
|
||||
absl::StrAppend(&str, "]");
|
||||
}
|
||||
|
||||
void operator()(const CapturingReplyBuilder::ScoredArray& sarr) {
|
||||
|
|
|
@ -766,4 +766,11 @@ async def test_http(df_server: DflyInstance):
|
|||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
assert text.strip() == '{"result":"МайяХилли"}'
|
||||
|
||||
body = '["foo", "bar"]'
|
||||
async with session.post(f"http://localhost:{df_server.port}/api", data=body) as resp:
|
||||
assert resp.status == 200
|
||||
text = await resp.text()
|
||||
assert text.strip() == '{"error": "unknown command `FOO`"}'
|
||||
|
||||
assert await client.ttl("foo") > 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue