mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
change ResponseError to Error
This commit is contained in:
parent
4c2af8e515
commit
e2db197b3f
11 changed files with 203 additions and 201 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue