fix the payload too large error

This commit is contained in:
Irevoire 2022-10-22 13:26:25 +02:00 committed by Tamo
parent 950606cd36
commit e0b6206097
3 changed files with 17 additions and 13 deletions

View file

@ -2,11 +2,12 @@ use std::pin::Pin;
use std::task::{Context, Poll};
use actix_http::encoding::Decoder as Decompress;
use actix_web::error::PayloadError;
use actix_web::{dev, web, FromRequest, HttpRequest};
use futures::future::{ready, Ready};
use futures::Stream;
use crate::error::MeilisearchHttpError;
pub struct Payload {
payload: Decompress<dev::Payload>,
limit: usize,
@ -29,7 +30,7 @@ impl Default for PayloadConfig {
}
impl FromRequest for Payload {
type Error = PayloadError;
type Error = MeilisearchHttpError;
type Future = Ready<Result<Payload, Self::Error>>;
@ -47,7 +48,7 @@ impl FromRequest for Payload {
}
impl Stream for Payload {
type Item = Result<web::Bytes, PayloadError>;
type Item = Result<web::Bytes, MeilisearchHttpError>;
#[inline]
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
@ -58,11 +59,11 @@ impl Stream for Payload {
self.limit = new_limit;
Poll::Ready(Some(Ok(bytes)))
}
None => Poll::Ready(Some(Err(PayloadError::Overflow))),
None => Poll::Ready(Some(Err(MeilisearchHttpError::PayloadTooLarge))),
},
x => Poll::Ready(Some(x)),
x => Poll::Ready(Some(x.map_err(MeilisearchHttpError::from))),
},
otherwise => otherwise,
otherwise => otherwise.map(|o| o.map(|o| o.map_err(MeilisearchHttpError::from))),
}
}
}