Merge pull request #42 from meilisearch/basic-error-handling

basic error handling
This commit is contained in:
marin 2021-02-16 16:38:25 +01:00 committed by GitHub
commit 4d9819f6ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 30 deletions

View File

@ -63,8 +63,7 @@ async fn get_document(
Ok(HttpResponse::Ok().body(json)) Ok(HttpResponse::Ok().body(json))
} }
Err(e) => { Err(e) => {
error!("{}", e); Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
unimplemented!()
} }
} }
} }
@ -83,8 +82,7 @@ async fn delete_document(
Ok(HttpResponse::Ok().body(json)) Ok(HttpResponse::Ok().body(json))
} }
Err(e) => { Err(e) => {
error!("{}", e); Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
unimplemented!()
} }
} }
} }
@ -120,7 +118,9 @@ async fn get_all_documents(
let json = serde_json::to_string(&docs).unwrap(); let json = serde_json::to_string(&docs).unwrap();
Ok(HttpResponse::Ok().body(json)) Ok(HttpResponse::Ok().body(json))
} }
Err(_) => { todo!() } Err(e) => {
Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
}
} }
} }
@ -158,8 +158,7 @@ async fn add_documents_json(
Ok(response) Ok(response)
} }
Err(e) => { Err(e) => {
error!("{}", e); Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
todo!()
} }
} }
} }
@ -216,8 +215,7 @@ async fn update_documents(
Ok(response) Ok(response)
} }
Err(e) => { Err(e) => {
error!("{}", e); Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
todo!()
} }
} }
} }
@ -242,8 +240,7 @@ async fn delete_documents(
Ok(HttpResponse::Ok().body(json)) Ok(HttpResponse::Ok().body(json))
} }
Err(e) => { Err(e) => {
error!("{}", e); Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
unimplemented!()
} }
} }
} }
@ -259,8 +256,7 @@ async fn clear_all_documents(
Ok(HttpResponse::Ok().body(json)) Ok(HttpResponse::Ok().body(json))
} }
Err(e) => { Err(e) => {
error!("{}", e); Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
unimplemented!();
} }
} }
} }

View File

@ -1,7 +1,6 @@
use actix_web::{delete, get, post, put}; use actix_web::{delete, get, post, put};
use actix_web::{web, HttpResponse}; use actix_web::{web, HttpResponse};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use log::error;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::Data; use crate::Data;
@ -28,8 +27,7 @@ async fn list_indexes(data: web::Data<Data>) -> Result<HttpResponse, ResponseErr
Ok(HttpResponse::Ok().body(&json)) Ok(HttpResponse::Ok().body(&json))
} }
Err(e) => { Err(e) => {
error!("error listing indexes: {}", e); Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
unimplemented!()
} }
} }
} }
@ -45,7 +43,8 @@ async fn get_index(
Ok(HttpResponse::Ok().body(json)) Ok(HttpResponse::Ok().body(json))
} }
None => { None => {
unimplemented!() let e = format!("Index {:?} doesn't exist.", path.index_uid);
Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
} }
} }
} }
@ -68,8 +67,7 @@ async fn create_index(
Ok(HttpResponse::Ok().body(json)) Ok(HttpResponse::Ok().body(json))
} }
Err(e) => { Err(e) => {
error!("error creating index: {}", e); Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
unimplemented!()
} }
} }
} }
@ -102,7 +100,9 @@ async fn update_index(
let json = serde_json::to_string(&meta).unwrap(); let json = serde_json::to_string(&meta).unwrap();
Ok(HttpResponse::Ok().body(json)) Ok(HttpResponse::Ok().body(json))
} }
Err(_) => { todo!() } Err(e) => {
Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
}
} }
} }
@ -114,8 +114,7 @@ async fn delete_index(
match data.delete_index(path.index_uid.clone()).await { match data.delete_index(path.index_uid.clone()).await {
Ok(_) => Ok(HttpResponse::Ok().finish()), Ok(_) => Ok(HttpResponse::Ok().finish()),
Err(e) => { Err(e) => {
error!("{}", e); Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
todo!()
} }
} }
} }
@ -141,11 +140,11 @@ async fn get_update_status(
Ok(HttpResponse::Ok().body(json)) Ok(HttpResponse::Ok().body(json))
} }
Ok(None) => { Ok(None) => {
todo!() let e = format!("udpate {} for index {:?} doesn't exists.", path.update_id, path.index_uid);
Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
} }
Err(e) => { Err(e) => {
error!("{}", e); Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
todo!()
} }
} }
} }
@ -162,8 +161,7 @@ async fn get_all_updates_status(
Ok(HttpResponse::Ok().body(json)) Ok(HttpResponse::Ok().body(json))
} }
Err(e) => { Err(e) => {
error!("{}", e); Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
todo!()
} }
} }
} }

View File

@ -1,5 +1,4 @@
use actix_web::{get, post, web, HttpResponse}; use actix_web::{get, post, web, HttpResponse};
use log::error;
use crate::error::ResponseError; use crate::error::ResponseError;
use crate::helpers::Authentication; use crate::helpers::Authentication;
@ -49,8 +48,7 @@ async fn search_with_post(
Ok(HttpResponse::Ok().body(docs)) Ok(HttpResponse::Ok().body(docs))
} }
Err(e) => { Err(e) => {
error!("{}", e); Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() })))
todo!()
} }
} }
} }