mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-05 04:28:55 +01:00
change ResponseError to Error
This commit is contained in:
parent
4c2af8e515
commit
e2db197b3f
@ -7,7 +7,7 @@ use serde_json::json;
|
||||
use actix_web::error::JsonPayloadError;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ResponseError {
|
||||
pub enum Error {
|
||||
BadParameter(String, String),
|
||||
BadRequest(String),
|
||||
CreateIndex(String),
|
||||
@ -63,69 +63,69 @@ impl fmt::Display for FacetCountError {
|
||||
}
|
||||
}
|
||||
|
||||
impl ResponseError {
|
||||
pub fn internal(err: impl fmt::Display) -> ResponseError {
|
||||
ResponseError::Internal(err.to_string())
|
||||
impl Error {
|
||||
pub fn internal(err: impl fmt::Display) -> Error {
|
||||
Error::Internal(err.to_string())
|
||||
}
|
||||
|
||||
pub fn bad_request(err: impl fmt::Display) -> ResponseError {
|
||||
ResponseError::BadRequest(err.to_string())
|
||||
pub fn bad_request(err: impl fmt::Display) -> Error {
|
||||
Error::BadRequest(err.to_string())
|
||||
}
|
||||
|
||||
pub fn missing_authorization_header() -> ResponseError {
|
||||
ResponseError::MissingAuthorizationHeader
|
||||
pub fn missing_authorization_header() -> Error {
|
||||
Error::MissingAuthorizationHeader
|
||||
}
|
||||
|
||||
pub fn invalid_token(err: impl fmt::Display) -> ResponseError {
|
||||
ResponseError::InvalidToken(err.to_string())
|
||||
pub fn invalid_token(err: impl fmt::Display) -> Error {
|
||||
Error::InvalidToken(err.to_string())
|
||||
}
|
||||
|
||||
pub fn not_found(err: impl fmt::Display) -> ResponseError {
|
||||
ResponseError::NotFound(err.to_string())
|
||||
pub fn not_found(err: impl fmt::Display) -> Error {
|
||||
Error::NotFound(err.to_string())
|
||||
}
|
||||
|
||||
pub fn index_not_found(err: impl fmt::Display) -> ResponseError {
|
||||
ResponseError::IndexNotFound(err.to_string())
|
||||
pub fn index_not_found(err: impl fmt::Display) -> Error {
|
||||
Error::IndexNotFound(err.to_string())
|
||||
}
|
||||
|
||||
pub fn document_not_found(err: impl fmt::Display) -> ResponseError {
|
||||
ResponseError::DocumentNotFound(err.to_string())
|
||||
pub fn document_not_found(err: impl fmt::Display) -> Error {
|
||||
Error::DocumentNotFound(err.to_string())
|
||||
}
|
||||
|
||||
pub fn missing_header(err: impl fmt::Display) -> ResponseError {
|
||||
ResponseError::MissingHeader(err.to_string())
|
||||
pub fn missing_header(err: impl fmt::Display) -> Error {
|
||||
Error::MissingHeader(err.to_string())
|
||||
}
|
||||
|
||||
pub fn bad_parameter(param: impl fmt::Display, err: impl fmt::Display) -> ResponseError {
|
||||
ResponseError::BadParameter(param.to_string(), err.to_string())
|
||||
pub fn bad_parameter(param: impl fmt::Display, err: impl fmt::Display) -> Error {
|
||||
Error::BadParameter(param.to_string(), err.to_string())
|
||||
}
|
||||
|
||||
pub fn open_index(err: impl fmt::Display) -> ResponseError {
|
||||
ResponseError::OpenIndex(err.to_string())
|
||||
pub fn open_index(err: impl fmt::Display) -> Error {
|
||||
Error::OpenIndex(err.to_string())
|
||||
}
|
||||
|
||||
pub fn create_index(err: impl fmt::Display) -> ResponseError {
|
||||
ResponseError::CreateIndex(err.to_string())
|
||||
pub fn create_index(err: impl fmt::Display) -> Error {
|
||||
Error::CreateIndex(err.to_string())
|
||||
}
|
||||
|
||||
pub fn invalid_index_uid() -> ResponseError {
|
||||
ResponseError::InvalidIndexUid
|
||||
pub fn invalid_index_uid() -> Error {
|
||||
Error::InvalidIndexUid
|
||||
}
|
||||
|
||||
pub fn maintenance() -> ResponseError {
|
||||
ResponseError::Maintenance
|
||||
pub fn maintenance() -> Error {
|
||||
Error::Maintenance
|
||||
}
|
||||
|
||||
pub fn retrieve_document(doc_id: u32, err: impl fmt::Display) -> ResponseError {
|
||||
ResponseError::RetrieveDocument(doc_id, err.to_string())
|
||||
pub fn retrieve_document(doc_id: u64, err: impl fmt::Display) -> Error {
|
||||
Error::RetrieveDocument(doc_id, err.to_string())
|
||||
}
|
||||
|
||||
pub fn search_documents(err: impl fmt::Display) -> ResponseError {
|
||||
ResponseError::SearchDocuments(err.to_string())
|
||||
pub fn search_documents(err: impl fmt::Display) -> Error {
|
||||
Error::SearchDocuments(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ResponseError {
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::BadParameter(param, err) => write!(f, "Url parameter {} error: {}", param, err),
|
||||
@ -152,7 +152,7 @@ impl fmt::Display for ResponseError {
|
||||
}
|
||||
}
|
||||
|
||||
impl aweb::error::ResponseError for ResponseError {
|
||||
impl aweb::error::ResponseError for Error {
|
||||
fn error_response(&self) -> aweb::HttpResponse {
|
||||
ResponseBuilder::new(self.status_code()).json(json!({
|
||||
"message": self.to_string(),
|
||||
@ -185,26 +185,26 @@ impl aweb::error::ResponseError for ResponseError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<meilisearch_core::HeedError> for ResponseError {
|
||||
fn from(err: meilisearch_core::HeedError) -> ResponseError {
|
||||
ResponseError::Internal(err.to_string())
|
||||
impl From<meilisearch_core::HeedError> for Error {
|
||||
fn from(err: meilisearch_core::HeedError) -> Error {
|
||||
Error::Internal(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<meilisearch_core::FstError> for ResponseError {
|
||||
fn from(err: meilisearch_core::FstError) -> ResponseError {
|
||||
ResponseError::Internal(err.to_string())
|
||||
impl From<meilisearch_core::FstError> for Error {
|
||||
fn from(err: meilisearch_core::FstError) -> Error {
|
||||
Error::Internal(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<meilisearch_core::FacetError> for ResponseError {
|
||||
fn from(error: meilisearch_core::FacetError) -> ResponseError {
|
||||
ResponseError::FacetExpression(error.to_string())
|
||||
impl From<meilisearch_core::FacetError> for Error {
|
||||
fn from(error: meilisearch_core::FacetError) -> Error {
|
||||
Error::FacetExpression(error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<meilisearch_core::Error> for ResponseError {
|
||||
fn from(err: meilisearch_core::Error) -> ResponseError {
|
||||
impl From<meilisearch_core::Error> for Error {
|
||||
fn from(err: meilisearch_core::Error) -> Error {
|
||||
use meilisearch_core::pest_error::LineColLocation::*;
|
||||
match err {
|
||||
meilisearch_core::Error::FilterParseError(e) => {
|
||||
@ -214,43 +214,43 @@ impl From<meilisearch_core::Error> for ResponseError {
|
||||
};
|
||||
let message = format!("parsing error on line {} at column {}: {}", line, column, e.variant.message());
|
||||
|
||||
ResponseError::FilterParsing(message)
|
||||
Error::FilterParsing(message)
|
||||
},
|
||||
meilisearch_core::Error::FacetError(e) => ResponseError::FacetExpression(e.to_string()),
|
||||
_ => ResponseError::Internal(err.to_string()),
|
||||
meilisearch_core::Error::FacetError(e) => Error::FacetExpression(e.to_string()),
|
||||
_ => Error::Internal(err.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<meilisearch_schema::Error> for ResponseError {
|
||||
fn from(err: meilisearch_schema::Error) -> ResponseError {
|
||||
ResponseError::Internal(err.to_string())
|
||||
impl From<meilisearch_schema::Error> for Error {
|
||||
fn from(err: meilisearch_schema::Error) -> Error {
|
||||
Error::Internal(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<actix_http::Error> for ResponseError {
|
||||
fn from(err: actix_http::Error) -> ResponseError {
|
||||
ResponseError::Internal(err.to_string())
|
||||
impl From<actix_http::Error> for Error {
|
||||
fn from(err: actix_http::Error) -> Error {
|
||||
Error::Internal(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FacetCountError> for ResponseError {
|
||||
fn from(other: FacetCountError) -> ResponseError {
|
||||
ResponseError::FacetCount(other.to_string())
|
||||
impl From<FacetCountError> for Error {
|
||||
fn from(other: FacetCountError) -> Error {
|
||||
Error::FacetCount(other.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<JsonPayloadError> for ResponseError {
|
||||
fn from(err: JsonPayloadError) -> ResponseError {
|
||||
impl From<JsonPayloadError> for Error {
|
||||
fn from(err: JsonPayloadError) -> Error {
|
||||
match err {
|
||||
JsonPayloadError::Deserialize(err) => ResponseError::BadRequest(format!("Invalid JSON: {}", err)),
|
||||
JsonPayloadError::Overflow => ResponseError::PayloadTooLarge,
|
||||
JsonPayloadError::ContentType => ResponseError::UnsupportedMediaType,
|
||||
JsonPayloadError::Payload(err) => ResponseError::BadRequest(format!("Problem while decoding the request: {}", err)),
|
||||
JsonPayloadError::Deserialize(err) => Error::BadRequest(format!("Invalid JSON: {}", err)),
|
||||
JsonPayloadError::Overflow => Error::PayloadTooLarge,
|
||||
JsonPayloadError::ContentType => Error::UnsupportedMediaType,
|
||||
JsonPayloadError::Payload(err) => Error::BadRequest(format!("Problem while decoding the request: {}", err)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn json_error_handler(err: JsonPayloadError) -> ResponseError {
|
||||
pub fn json_error_handler(err: JsonPayloadError) -> Error {
|
||||
err.into()
|
||||
}
|
||||
|
@ -4,10 +4,10 @@ use std::rc::Rc;
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
use actix_service::{Service, Transform};
|
||||
use actix_web::{dev::ServiceRequest, dev::ServiceResponse, Error};
|
||||
use actix_web::{dev::ServiceRequest, dev::ServiceResponse};
|
||||
use futures::future::{err, ok, Future, Ready};
|
||||
|
||||
use crate::error::ResponseError;
|
||||
use crate::error::Error;
|
||||
use crate::Data;
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -19,13 +19,13 @@ pub enum Authentication {
|
||||
|
||||
impl<S: 'static, B> Transform<S> for Authentication
|
||||
where
|
||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = actix_web::Error>,
|
||||
S::Future: 'static,
|
||||
B: 'static,
|
||||
{
|
||||
type Request = ServiceRequest;
|
||||
type Response = ServiceResponse<B>;
|
||||
type Error = Error;
|
||||
type Error = actix_web::Error;
|
||||
type InitError = ();
|
||||
type Transform = LoggingMiddleware<S>;
|
||||
type Future = Ready<Result<Self::Transform, Self::InitError>>;
|
||||
@ -45,13 +45,13 @@ pub struct LoggingMiddleware<S> {
|
||||
|
||||
impl<S, B> Service for LoggingMiddleware<S>
|
||||
where
|
||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
|
||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = actix_web::Error> + 'static,
|
||||
S::Future: 'static,
|
||||
B: 'static,
|
||||
{
|
||||
type Request = ServiceRequest;
|
||||
type Response = ServiceResponse<B>;
|
||||
type Error = Error;
|
||||
type Error = actix_web::Error;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
|
||||
@ -71,10 +71,10 @@ where
|
||||
let auth_header = match req.headers().get("X-Meili-API-Key") {
|
||||
Some(auth) => match auth.to_str() {
|
||||
Ok(auth) => auth,
|
||||
Err(_) => return Box::pin(err(ResponseError::MissingAuthorizationHeader.into())),
|
||||
Err(_) => return Box::pin(err(Error::MissingAuthorizationHeader.into())),
|
||||
},
|
||||
None => {
|
||||
return Box::pin(err(ResponseError::MissingAuthorizationHeader.into()));
|
||||
return Box::pin(err(Error::MissingAuthorizationHeader.into()));
|
||||
}
|
||||
};
|
||||
|
||||
@ -95,7 +95,7 @@ where
|
||||
Box::pin(svc.call(req))
|
||||
} else {
|
||||
Box::pin(err(
|
||||
ResponseError::InvalidToken(auth_header.to_string()).into()
|
||||
Error::InvalidToken(auth_header.to_string()).into()
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ use serde_json::Value;
|
||||
use siphasher::sip::SipHasher;
|
||||
use slice_group_by::GroupBy;
|
||||
|
||||
use crate::error::ResponseError;
|
||||
use crate::error::Error;
|
||||
|
||||
pub trait IndexSearchExt {
|
||||
fn new_search(&self, query: String) -> SearchBuilder;
|
||||
@ -107,12 +107,12 @@ impl<'a> SearchBuilder<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn search(self, reader: &heed::RoTxn<MainT>) -> Result<SearchResult, ResponseError> {
|
||||
pub fn search(self, reader: &heed::RoTxn<MainT>) -> Result<SearchResult, Error> {
|
||||
let schema = self
|
||||
.index
|
||||
.main
|
||||
.schema(reader)?
|
||||
.ok_or(ResponseError::internal("missing schema"))?;
|
||||
.ok_or(Error::internal("missing schema"))?;
|
||||
|
||||
let ranked_map = self.index.main.ranked_map(reader)?.unwrap_or_default();
|
||||
|
||||
@ -159,7 +159,7 @@ impl<'a> SearchBuilder<'a> {
|
||||
|
||||
let start = Instant::now();
|
||||
let result = query_builder.query(reader, &self.query, self.offset..(self.offset + self.limit));
|
||||
let search_result = result.map_err(ResponseError::search_documents)?;
|
||||
let search_result = result.map_err(Error::search_documents)?;
|
||||
let time_ms = start.elapsed().as_millis() as usize;
|
||||
|
||||
let mut all_attributes: HashSet<&str> = HashSet::new();
|
||||
@ -194,8 +194,8 @@ impl<'a> SearchBuilder<'a> {
|
||||
let mut document: IndexMap<String, Value> = self
|
||||
.index
|
||||
.document(reader, Some(&all_attributes), doc.id)
|
||||
.map_err(|e| ResponseError::retrieve_document(doc.id.0, e))?
|
||||
.ok_or(ResponseError::internal(
|
||||
.map_err(|e| Error::retrieve_document(doc.id.0, e))?
|
||||
.ok_or(Error::internal(
|
||||
"Impossible to retrieve the document; Corrupted data",
|
||||
))?;
|
||||
|
||||
@ -260,7 +260,7 @@ impl<'a> SearchBuilder<'a> {
|
||||
reader: &heed::RoTxn<MainT>,
|
||||
ranked_map: &'a RankedMap,
|
||||
schema: &Schema,
|
||||
) -> Result<Option<Criteria<'a>>, ResponseError> {
|
||||
) -> Result<Option<Criteria<'a>>, Error> {
|
||||
let ranking_rules = self.index.main.ranking_rules(reader)?;
|
||||
|
||||
if let Some(ranking_rules) = ranking_rules {
|
||||
|
@ -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 ¶ms.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()?;
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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()?;
|
||||
|
||||
|
@ -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()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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()?;
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user