correct error code while deleting stopwords

This commit is contained in:
krunal 2023-12-04 12:01:56 +05:30
parent 1c815c25e6
commit 4790cbbb3b
3 changed files with 8 additions and 7 deletions

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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();