mirror of
https://github.com/typesense/typesense.git
synced 2025-05-19 21:22:25 +08:00
correct error code while deleting stopwords
This commit is contained in:
parent
1c815c25e6
commit
4790cbbb3b
@ -2238,7 +2238,7 @@ bool del_stopword(const std::shared_ptr<http_req>& req, const std::shared_ptr<ht
|
||||
Option<bool> delete_op = stopwordManager.delete_stopword(stopword_name);
|
||||
|
||||
if(!delete_op.ok()) {
|
||||
res->set_500(delete_op.error());
|
||||
res->set(delete_op.code(), delete_op.error());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -80,16 +80,17 @@ std::string StopwordsManager::get_stopword_key(const std::string& stopword_name)
|
||||
Option<bool> StopwordsManager::delete_stopword(const std::string& stopword_name) {
|
||||
std::unique_lock lock(mutex);
|
||||
|
||||
bool removed = store->remove(get_stopword_key(stopword_name));
|
||||
if(!removed) {
|
||||
return Option<bool>(500, "Unable to delete from store.");
|
||||
}
|
||||
|
||||
if(stopword_configs.find(stopword_name) == stopword_configs.end()) {
|
||||
return Option<bool>(404, "Stopword `" + stopword_name + "` not found.");
|
||||
}
|
||||
|
||||
stopword_configs.erase(stopword_name);
|
||||
|
||||
bool removed = store->remove(get_stopword_key(stopword_name));
|
||||
if(!removed) {
|
||||
return Option<bool>(500, "Unable to delete from store.");
|
||||
}
|
||||
|
||||
return Option<bool>(true);
|
||||
}
|
||||
|
||||
|
@ -281,7 +281,7 @@ TEST_F(StopwordsManagerTest, StopwordsBasics) {
|
||||
req->params["name"] = "state";
|
||||
|
||||
result = del_stopword(req, res);
|
||||
ASSERT_EQ(500, res->status_code);
|
||||
ASSERT_EQ(404, res->status_code);
|
||||
ASSERT_STREQ("{\"message\": \"Stopword `state` not found.\"}", res->body.c_str());
|
||||
|
||||
req->params.clear();
|
||||
|
Loading…
x
Reference in New Issue
Block a user