change ResponseError to Error

This commit is contained in:
mpostma 2020-05-19 18:20:29 +02:00
parent 4c2af8e515
commit e2db197b3f
11 changed files with 203 additions and 201 deletions

View file

@ -7,7 +7,7 @@ use meilisearch_core::update;
use serde::Deserialize;
use serde_json::Value;
use crate::error::ResponseError;
use crate::error::Error;
use crate::helpers::Authentication;
use crate::routes::{IndexParam, IndexUpdateResponse};
use crate::Data;
@ -37,11 +37,11 @@ pub fn services(cfg: &mut web::ServiceConfig) {
async fn get_document(
data: web::Data<Data>,
path: web::Path<DocumentParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let reader = data.db.main_read_txn()?;
let internal_id = index.main
@ -49,8 +49,8 @@ async fn get_document(
.ok_or(ResponseError::document_not_found(&path.document_id))?;
let response: Document = index
.document(&reader, None, internal_id)?
.ok_or(ResponseError::document_not_found(&path.document_id))?;
.document(&reader, None, document_id)?
.ok_or(Error::document_not_found(&path.document_id))?;
Ok(HttpResponse::Ok().json(response))
}
@ -62,11 +62,13 @@ async fn get_document(
async fn delete_document(
data: web::Data<Data>,
path: web::Path<DocumentParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let document_id = meilisearch_core::serde::compute_document_id(&path.document_id);
let mut update_writer = data.db.update_write_txn()?;
@ -93,11 +95,11 @@ async fn get_all_documents(
data: web::Data<Data>,
path: web::Path<IndexParam>,
params: web::Query<BrowseQuery>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let offset = params.offset.unwrap_or(0);
let limit = params.limit.unwrap_or(20);
@ -151,18 +153,18 @@ async fn update_multiple_documents(
params: web::Query<UpdateDocumentsQuery>,
body: web::Json<Vec<Document>>,
is_partial: bool,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let reader = data.db.main_read_txn()?;
let mut schema = index
.main
.schema(&reader)?
.ok_or(ResponseError::internal("Impossible to retrieve the schema"))?;
.ok_or(Error::internal("Impossible to retrieve the schema"))?;
if schema.primary_key().is_none() {
let id = match &params.primary_key {
@ -170,14 +172,14 @@ async fn update_multiple_documents(
None => body
.first()
.and_then(find_primary_key)
.ok_or(ResponseError::bad_request("Could not infer a primary key"))?,
.ok_or(Error::bad_request("Could not infer a primary key"))?,
};
let mut writer = data.db.main_write_txn()?;
schema
.set_primary_key(&id)
.map_err(ResponseError::bad_request)?;
.map_err(Error::bad_request)?;
index.main.put_schema(&mut writer, &schema)?;
writer.commit()?;
}
@ -205,7 +207,7 @@ async fn add_documents(
path: web::Path<IndexParam>,
params: web::Query<UpdateDocumentsQuery>,
body: web::Json<Vec<Document>>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
update_multiple_documents(data, path, params, body, false).await
}
@ -215,7 +217,7 @@ async fn update_documents(
path: web::Path<IndexParam>,
params: web::Query<UpdateDocumentsQuery>,
body: web::Json<Vec<Document>>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
update_multiple_documents(data, path, params, body, true).await
}
@ -227,11 +229,11 @@ async fn delete_documents(
data: web::Data<Data>,
path: web::Path<IndexParam>,
body: web::Json<Vec<Value>>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let mut writer = data.db.update_write_txn()?;
@ -253,11 +255,11 @@ async fn delete_documents(
async fn clear_all_documents(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let mut writer = data.db.update_write_txn()?;

View file

@ -3,7 +3,7 @@ use actix_web_macros::{get, put};
use heed::types::{Str, Unit};
use serde::Deserialize;
use crate::error::ResponseError;
use crate::error::Error;
use crate::helpers::Authentication;
use crate::Data;
@ -14,19 +14,19 @@ pub fn services(cfg: &mut web::ServiceConfig) {
}
#[get("/health", wrap = "Authentication::Private")]
async fn get_health(data: web::Data<Data>) -> Result<HttpResponse, ResponseError> {
async fn get_health(data: web::Data<Data>) -> Result<HttpResponse, Error> {
let reader = data.db.main_read_txn()?;
let common_store = data.db.common_store();
if let Ok(Some(_)) = common_store.get::<_, Str, Unit>(&reader, UNHEALTHY_KEY) {
return Err(ResponseError::Maintenance);
return Err(Error::Maintenance);
}
Ok(HttpResponse::Ok().finish())
}
async fn set_healthy(data: web::Data<Data>) -> Result<HttpResponse, ResponseError> {
async fn set_healthy(data: web::Data<Data>) -> Result<HttpResponse, Error> {
let mut writer = data.db.main_write_txn()?;
let common_store = data.db.common_store();
common_store.delete::<_, Str>(&mut writer, UNHEALTHY_KEY)?;
@ -35,7 +35,7 @@ async fn set_healthy(data: web::Data<Data>) -> Result<HttpResponse, ResponseErro
Ok(HttpResponse::Ok().finish())
}
async fn set_unhealthy(data: web::Data<Data>) -> Result<HttpResponse, ResponseError> {
async fn set_unhealthy(data: web::Data<Data>) -> Result<HttpResponse, Error> {
let mut writer = data.db.main_write_txn()?;
let common_store = data.db.common_store();
common_store.put::<_, Str, Unit>(&mut writer, UNHEALTHY_KEY, &())?;
@ -53,7 +53,7 @@ struct HealthBody {
async fn change_healthyness(
data: web::Data<Data>,
body: web::Json<HealthBody>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
if body.health {
set_healthy(data).await
} else {

View file

@ -5,7 +5,7 @@ use log::error;
use rand::seq::SliceRandom;
use serde::{Deserialize, Serialize};
use crate::error::ResponseError;
use crate::error::Error;
use crate::helpers::Authentication;
use crate::routes::IndexParam;
use crate::Data;
@ -40,7 +40,7 @@ struct IndexResponse {
}
#[get("/indexes", wrap = "Authentication::Private")]
async fn list_indexes(data: web::Data<Data>) -> Result<HttpResponse, ResponseError> {
async fn list_indexes(data: web::Data<Data>) -> Result<HttpResponse, Error> {
let reader = data.db.main_read_txn()?;
let mut response = Vec::new();
@ -50,19 +50,19 @@ async fn list_indexes(data: web::Data<Data>) -> Result<HttpResponse, ResponseErr
match index {
Some(index) => {
let name = index.main.name(&reader)?.ok_or(ResponseError::internal(
let name = index.main.name(&reader)?.ok_or(Error::internal(
"Impossible to get the name of an index",
))?;
let created_at = index
.main
.created_at(&reader)?
.ok_or(ResponseError::internal(
.ok_or(Error::internal(
"Impossible to get the create date of an index",
))?;
let updated_at = index
.main
.updated_at(&reader)?
.ok_or(ResponseError::internal(
.ok_or(Error::internal(
"Impossible to get the last update date of an index",
))?;
@ -97,27 +97,27 @@ async fn list_indexes(data: web::Data<Data>) -> Result<HttpResponse, ResponseErr
async fn get_index(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let reader = data.db.main_read_txn()?;
let name = index.main.name(&reader)?.ok_or(ResponseError::internal(
let name = index.main.name(&reader)?.ok_or(Error::internal(
"Impossible to get the name of an index",
))?;
let created_at = index
.main
.created_at(&reader)?
.ok_or(ResponseError::internal(
.ok_or(Error::internal(
"Impossible to get the create date of an index",
))?;
let updated_at = index
.main
.updated_at(&reader)?
.ok_or(ResponseError::internal(
.ok_or(Error::internal(
"Impossible to get the last update date of an index",
))?;
@ -150,9 +150,9 @@ struct IndexCreateRequest {
async fn create_index(
data: web::Data<Data>,
body: web::Json<IndexCreateRequest>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
if let (None, None) = (body.name.clone(), body.uid.clone()) {
return Err(ResponseError::bad_request(
return Err(Error::bad_request(
"Index creation must have an uid",
));
}
@ -165,7 +165,7 @@ async fn create_index(
{
uid.to_owned()
} else {
return Err(ResponseError::InvalidIndexUid);
return Err(Error::InvalidIndexUid);
}
}
None => loop {
@ -179,7 +179,7 @@ async fn create_index(
let created_index = data
.db
.create_index(&uid)
.map_err(ResponseError::create_index)?;
.map_err(Error::create_index)?;
let mut writer = data.db.main_write_txn()?;
@ -189,18 +189,18 @@ async fn create_index(
let created_at = created_index
.main
.created_at(&writer)?
.ok_or(ResponseError::internal("Impossible to read created at"))?;
.ok_or(Error::internal("Impossible to read created at"))?;
let updated_at = created_index
.main
.updated_at(&writer)?
.ok_or(ResponseError::internal("Impossible to read updated at"))?;
.ok_or(Error::internal("Impossible to read updated at"))?;
if let Some(id) = body.primary_key.clone() {
if let Some(mut schema) = created_index.main.schema(&writer)? {
schema
.set_primary_key(&id)
.map_err(ResponseError::bad_request)?;
.map_err(Error::bad_request)?;
created_index.main.put_schema(&mut writer, &schema)?;
}
}
@ -238,11 +238,11 @@ async fn update_index(
data: web::Data<Data>,
path: web::Path<IndexParam>,
body: web::Json<IndexCreateRequest>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let mut writer = data.db.main_write_txn()?;
@ -254,7 +254,7 @@ async fn update_index(
if let Some(mut schema) = index.main.schema(&writer)? {
match schema.primary_key() {
Some(_) => {
return Err(ResponseError::bad_request(
return Err(Error::bad_request(
"The primary key cannot be updated",
));
}
@ -271,19 +271,19 @@ async fn update_index(
let reader = data.db.main_read_txn()?;
let name = index.main.name(&reader)?.ok_or(ResponseError::internal(
let name = index.main.name(&reader)?.ok_or(Error::internal(
"Impossible to get the name of an index",
))?;
let created_at = index
.main
.created_at(&reader)?
.ok_or(ResponseError::internal(
.ok_or(Error::internal(
"Impossible to get the create date of an index",
))?;
let updated_at = index
.main
.updated_at(&reader)?
.ok_or(ResponseError::internal(
.ok_or(Error::internal(
"Impossible to get the last update date of an index",
))?;
@ -308,7 +308,7 @@ async fn update_index(
async fn delete_index(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
data.db.delete_index(&path.index_uid)?;
Ok(HttpResponse::NoContent().finish())
@ -327,11 +327,11 @@ struct UpdateParam {
async fn get_update_status(
data: web::Data<Data>,
path: web::Path<UpdateParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let reader = data.db.update_read_txn()?;
@ -339,7 +339,7 @@ async fn get_update_status(
match status {
Some(status) => Ok(HttpResponse::Ok().json(status)),
None => Err(ResponseError::NotFound(format!(
None => Err(Error::NotFound(format!(
"Update {} not found",
path.update_id
))),
@ -350,11 +350,11 @@ async fn get_update_status(
async fn get_all_updates_status(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let reader = data.db.update_read_txn()?;

View file

@ -7,7 +7,7 @@ use actix_web_macros::get;
use serde::Deserialize;
use serde_json::Value;
use crate::error::{ResponseError, FacetCountError};
use crate::error::{Error, FacetCountError};
use crate::helpers::meilisearch::IndexSearchExt;
use crate::helpers::Authentication;
use crate::routes::IndexParam;
@ -41,18 +41,18 @@ async fn search_with_url_query(
data: web::Data<Data>,
path: web::Path<IndexParam>,
params: web::Query<SearchQuery>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let reader = data.db.main_read_txn()?;
let schema = index
.main
.schema(&reader)?
.ok_or(ResponseError::internal("Impossible to retrieve the schema"))?;
.ok_or(Error::internal("Impossible to retrieve the schema"))?;
let mut search_builder = index.new_search(params.q.clone());
@ -90,7 +90,7 @@ async fn search_with_url_query(
if let Some(ref facet_filters) = params.facet_filters {
match index.main.attributes_for_faceting(&reader)? {
Some(ref attrs) => { search_builder.add_facet_filters(FacetFilter::from_str(facet_filters, &schema, attrs)?); },
None => return Err(ResponseError::FacetExpression("can't filter on facets, as no facet is set".to_string()))
None => return Err(Error::FacetExpression("can't filter on facets, as no facet is set".to_string()))
}
}

View file

@ -3,7 +3,7 @@ use actix_web_macros::{delete, get, post};
use meilisearch_core::settings::{Settings, SettingsUpdate, UpdateState, DEFAULT_RANKING_RULES};
use std::collections::{BTreeMap, BTreeSet, HashSet};
use crate::error::ResponseError;
use crate::error::Error;
use crate::helpers::Authentication;
use crate::routes::{IndexParam, IndexUpdateResponse};
use crate::Data;
@ -33,17 +33,17 @@ async fn update_all(
data: web::Data<Data>,
path: web::Path<IndexParam>,
body: web::Json<Settings>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let mut writer = data.db.update_write_txn()?;
let settings = body
.into_inner()
.into_update()
.map_err(ResponseError::bad_request)?;
.map_err(Error::bad_request)?;
let update_id = index.settings_update(&mut writer, settings)?;
writer.commit()?;
@ -54,11 +54,11 @@ async fn update_all(
async fn get_all(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let reader = data.db.main_read_txn()?;
@ -134,11 +134,11 @@ async fn get_all(
async fn delete_all(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let mut writer = data.db.update_write_txn()?;
let settings = SettingsUpdate {
@ -166,11 +166,11 @@ async fn delete_all(
async fn get_rules(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let reader = data.db.main_read_txn()?;
let ranking_rules = index
@ -192,11 +192,11 @@ async fn update_rules(
data: web::Data<Data>,
path: web::Path<IndexParam>,
body: web::Json<Option<Vec<String>>>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let settings = Settings {
ranking_rules: Some(body.into_inner()),
@ -204,7 +204,7 @@ async fn update_rules(
};
let mut writer = data.db.update_write_txn()?;
let settings = settings.into_update().map_err(ResponseError::bad_request)?;
let settings = settings.into_update().map_err(Error::bad_request)?;
let update_id = index.settings_update(&mut writer, settings)?;
writer.commit()?;
@ -218,11 +218,11 @@ async fn update_rules(
async fn delete_rules(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let mut writer = data.db.update_write_txn()?;
let settings = SettingsUpdate {
@ -244,11 +244,11 @@ async fn delete_rules(
async fn get_distinct(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let reader = data.db.main_read_txn()?;
let distinct_attribute = index.main.distinct_attribute(&reader)?;
@ -263,11 +263,11 @@ async fn update_distinct(
data: web::Data<Data>,
path: web::Path<IndexParam>,
body: web::Json<Option<String>>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let settings = Settings {
distinct_attribute: Some(body.into_inner()),
@ -275,7 +275,7 @@ async fn update_distinct(
};
let mut writer = data.db.update_write_txn()?;
let settings = settings.into_update().map_err(ResponseError::bad_request)?;
let settings = settings.into_update().map_err(Error::bad_request)?;
let update_id = index.settings_update(&mut writer, settings)?;
writer.commit()?;
@ -289,11 +289,11 @@ async fn update_distinct(
async fn delete_distinct(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let mut writer = data.db.update_write_txn()?;
let settings = SettingsUpdate {
@ -315,11 +315,11 @@ async fn delete_distinct(
async fn get_searchable(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let reader = data.db.main_read_txn()?;
let schema = index.main.schema(&reader)?;
let searchable_attributes: Option<Vec<String>> =
@ -336,11 +336,11 @@ async fn update_searchable(
data: web::Data<Data>,
path: web::Path<IndexParam>,
body: web::Json<Option<Vec<String>>>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let settings = Settings {
searchable_attributes: Some(body.into_inner()),
@ -348,7 +348,7 @@ async fn update_searchable(
};
let mut writer = data.db.update_write_txn()?;
let settings = settings.into_update().map_err(ResponseError::bad_request)?;
let settings = settings.into_update().map_err(Error::bad_request)?;
let update_id = index.settings_update(&mut writer, settings)?;
writer.commit()?;
@ -362,11 +362,11 @@ async fn update_searchable(
async fn delete_searchable(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let settings = SettingsUpdate {
searchable_attributes: UpdateState::Clear,
@ -387,11 +387,11 @@ async fn delete_searchable(
async fn get_displayed(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let reader = data.db.main_read_txn()?;
let schema = index.main.schema(&reader)?;
@ -410,11 +410,11 @@ async fn update_displayed(
data: web::Data<Data>,
path: web::Path<IndexParam>,
body: web::Json<Option<HashSet<String>>>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let settings = Settings {
displayed_attributes: Some(body.into_inner()),
@ -422,7 +422,7 @@ async fn update_displayed(
};
let mut writer = data.db.update_write_txn()?;
let settings = settings.into_update().map_err(ResponseError::bad_request)?;
let settings = settings.into_update().map_err(Error::bad_request)?;
let update_id = index.settings_update(&mut writer, settings)?;
writer.commit()?;
@ -436,11 +436,11 @@ async fn update_displayed(
async fn delete_displayed(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let settings = SettingsUpdate {
displayed_attributes: UpdateState::Clear,
@ -461,11 +461,11 @@ async fn delete_displayed(
async fn get_accept_new_fields(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let reader = data.db.main_read_txn()?;
let schema = index.main.schema(&reader)?;
@ -483,11 +483,11 @@ async fn update_accept_new_fields(
data: web::Data<Data>,
path: web::Path<IndexParam>,
body: web::Json<Option<bool>>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let settings = Settings {
accept_new_fields: Some(body.into_inner()),
@ -495,7 +495,7 @@ async fn update_accept_new_fields(
};
let mut writer = data.db.update_write_txn()?;
let settings = settings.into_update().map_err(ResponseError::bad_request)?;
let settings = settings.into_update().map_err(Error::bad_request)?;
let update_id = index.settings_update(&mut writer, settings)?;
writer.commit()?;

View file

@ -10,7 +10,7 @@ use serde::Serialize;
use sysinfo::{NetworkExt, ProcessExt, ProcessorExt, System, SystemExt};
use walkdir::WalkDir;
use crate::error::ResponseError;
use crate::error::Error;
use crate::helpers::Authentication;
use crate::routes::IndexParam;
use crate::Data;
@ -35,11 +35,11 @@ struct IndexStatsResponse {
async fn index_stats(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let reader = data.db.main_read_txn()?;
@ -51,7 +51,7 @@ async fn index_stats(
let is_indexing =
data.is_indexing(&update_reader, &path.index_uid)?
.ok_or(ResponseError::internal(
.ok_or(Error::internal(
"Impossible to know if the database is indexing",
))?;
@ -71,7 +71,7 @@ struct StatsResult {
}
#[get("/stats", wrap = "Authentication::Private")]
async fn get_stats(data: web::Data<Data>) -> Result<HttpResponse, ResponseError> {
async fn get_stats(data: web::Data<Data>) -> Result<HttpResponse, Error> {
let mut index_list = HashMap::new();
let reader = data.db.main_read_txn()?;
@ -87,7 +87,7 @@ async fn get_stats(data: web::Data<Data>) -> Result<HttpResponse, ResponseError>
let fields_distribution = index.main.fields_distribution(&reader)?.unwrap_or_default();
let is_indexing = data.is_indexing(&update_reader, &index_uid)?.ok_or(
ResponseError::internal("Impossible to know if the database is indexing"),
Error::internal("Impossible to know if the database is indexing"),
)?;
let response = IndexStatsResponse {

View file

@ -3,7 +3,7 @@ use actix_web_macros::{delete, get, post};
use meilisearch_core::settings::{SettingsUpdate, UpdateState};
use std::collections::BTreeSet;
use crate::error::ResponseError;
use crate::error::Error;
use crate::helpers::Authentication;
use crate::routes::{IndexParam, IndexUpdateResponse};
use crate::Data;
@ -19,11 +19,11 @@ pub fn services(cfg: &mut web::ServiceConfig) {
async fn get(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let reader = data.db.main_read_txn()?;
let stop_words_fst = index.main.stop_words_fst(&reader)?;
let stop_words = stop_words_fst.stream().into_strs()?;
@ -39,11 +39,11 @@ async fn update(
data: web::Data<Data>,
path: web::Path<IndexParam>,
body: web::Json<BTreeSet<String>>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let settings = SettingsUpdate {
stop_words: UpdateState::Update(body.into_inner()),
@ -64,11 +64,11 @@ async fn update(
async fn delete(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let settings = SettingsUpdate {
stop_words: UpdateState::Clear,

View file

@ -5,7 +5,7 @@ use actix_web_macros::{delete, get, post};
use indexmap::IndexMap;
use meilisearch_core::settings::{SettingsUpdate, UpdateState};
use crate::error::ResponseError;
use crate::error::Error;
use crate::helpers::Authentication;
use crate::routes::{IndexParam, IndexUpdateResponse};
use crate::Data;
@ -21,11 +21,11 @@ pub fn services(cfg: &mut web::ServiceConfig) {
async fn get(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let reader = data.db.main_read_txn()?;
@ -51,11 +51,11 @@ async fn update(
data: web::Data<Data>,
path: web::Path<IndexParam>,
body: web::Json<BTreeMap<String, Vec<String>>>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let settings = SettingsUpdate {
synonyms: UpdateState::Update(body.into_inner()),
@ -76,11 +76,11 @@ async fn update(
async fn delete(
data: web::Data<Data>,
path: web::Path<IndexParam>,
) -> Result<HttpResponse, ResponseError> {
) -> Result<HttpResponse, Error> {
let index = data
.db
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
.ok_or(Error::index_not_found(&path.index_uid))?;
let settings = SettingsUpdate {
synonyms: UpdateState::Clear,