about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBaitinq <manuelpalenzuelamerino@gmail.com>2022-10-25 02:06:32 +0200
committerBaitinq <manuelpalenzuelamerino@gmail.com>2022-10-25 02:06:32 +0200
commit39768de59f0f0df801db73943b3726598031ad8a (patch)
tree599029552b53beba5339ca2701404b28318869ec
parentCrawler: Shuffle crawled urls (diff)
downloadOSSE-39768de59f0f0df801db73943b3726598031ad8a.tar.gz
OSSE-39768de59f0f0df801db73943b3726598031ad8a.tar.bz2
OSSE-39768de59f0f0df801db73943b3726598031ad8a.zip
Indexer: Add "correct" error handling
-rw-r--r--indexer/src/main.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/indexer/src/main.rs b/indexer/src/main.rs
index 43a5f7f..4d88f0a 100644
--- a/indexer/src/main.rs
+++ b/indexer/src/main.rs
@@ -21,7 +21,7 @@ async fn serve_http_endpoint(address: &str, port: u16) -> std::io::Result<()> {
     HttpServer::new(move || {
         App::new()
             .app_data(shared_state.clone())
-            .service(greet)
+            .service(search)
             .service(add_resource)
     })
     .bind((address, port))?
@@ -67,17 +67,17 @@ async fn add_resource(data: web::Data<AppState>, resource: web::Json<Resource>)
 }
 
 #[get("/search/{term}")]
-async fn greet(data: web::Data<AppState>, term: web::Path<String>) -> impl Responder {
+async fn search(data: web::Data<AppState>, term: web::Path<String>) -> impl Responder {
     let query: Vec<&str> = term.split(' ').collect();
     let database = data.database.lock().unwrap();
 
     let mut valid_results: Option<HashSet<String>> = None;
     for w in query {
-        let curr_word_results = database.get(w);
-        if curr_word_results.is_none() {
-            return format!("No results found for {:?}!", w);
-        }
-        let curr_word_results = curr_word_results.unwrap();
+        let curr_word_results = match database.get(w) {
+            None => return format!("No results found for {:?}!", w),
+            Some(results) => results,
+        };
+
         match valid_results {
             None => {
                 valid_results = Some(curr_word_results.clone());