Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Address unhandled errors during writes.

Kishore Nallan2e010e142a42
diff --git a/src/batched_indexer.cpp b/src/batched_indexer.cpp
index 4d25f976..5f66c8b6 100644
--- a/src/batched_indexer.cpp
+++ b/src/batched_indexer.cpp
@@ -190,14 +190,22 @@ void BatchedIndexer::run() {
if(route_found) {
async_res = found_rpath->async_res;
- found_rpath->handler(orig_req, orig_res);
+ try {
+ found_rpath->handler(orig_req, orig_res);
+ } catch(const std::exception& e) {
+ LOG(ERROR) << "Exception while calling handler " << found_rpath->_get_action();
+ LOG(ERROR) << "Raw error: " << e.what();
+ // bad request gets a response immediately
+ orig_res->set_400("Bad request.");
+ async_res = false;
+ }
prev_body = orig_req->body;
} else {
orig_res->set_404();
}
if(is_live_req && (!route_found ||!async_res)) {
- // sync request get a response immediately
+ // sync request gets a response immediately
async_req_res_t* async_req_res = new async_req_res_t(orig_req, orig_res, true);
server->get_message_dispatcher()->send_message(HttpServer::STREAM_RESPONSE_MESSAGE, async_req_res);
}
diff --git a/src/core_api.cpp b/src/core_api.cpp
index 10f8b6ff..934c0dd0 100644
--- a/src/core_api.cpp
+++ b/src/core_api.cpp
@@ -1421,6 +1421,11 @@ bool put_synonym(const std::shared_ptr<http_req>& req, const std::shared_ptr<htt
return false;
}
+ if(!syn_json.is_object()) {
+ res->set_400("Bad JSON.");
+ return false;
+ }
+
syn_json["id"] = synonym_id;
synonym_t synonym;