mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 23:04:26 +01:00
error change and tokio file use change
This commit is contained in:
parent
6766712840
commit
35f3dd68b6
@ -95,8 +95,8 @@ pub enum PayloadError {
|
|||||||
MalformedPayload(serde_json::error::Error),
|
MalformedPayload(serde_json::error::Error),
|
||||||
#[error("A json payload is missing.")]
|
#[error("A json payload is missing.")]
|
||||||
MissingPayload,
|
MissingPayload,
|
||||||
#[error("Exception when accepting a playload to a temporary file")]
|
#[error("Error while writing the playload to disk: `{0}`.")]
|
||||||
ReceivePayloadErr,
|
ReceivePayloadErr(Box<dyn std::error::Error + Send + Sync + 'static>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ErrorCode for PayloadError {
|
impl ErrorCode for PayloadError {
|
||||||
@ -128,7 +128,7 @@ impl ErrorCode for PayloadError {
|
|||||||
},
|
},
|
||||||
PayloadError::MissingPayload => Code::MissingPayload,
|
PayloadError::MissingPayload => Code::MissingPayload,
|
||||||
PayloadError::MalformedPayload(_) => Code::MalformedPayload,
|
PayloadError::MalformedPayload(_) => Code::MalformedPayload,
|
||||||
PayloadError::ReceivePayloadErr => Code::Internal,
|
PayloadError::ReceivePayloadErr(_) => Code::Internal,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use actix_web::{web, HttpMessage, HttpRequest, HttpResponse};
|
|||||||
use bstr::ByteSlice;
|
use bstr::ByteSlice;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use index_scheduler::IndexScheduler;
|
use index_scheduler::IndexScheduler;
|
||||||
use log::{debug, error};
|
use log::debug;
|
||||||
use meilisearch_types::document_formats::{read_csv, read_json, read_ndjson, PayloadType};
|
use meilisearch_types::document_formats::{read_csv, read_json, read_ndjson, PayloadType};
|
||||||
use meilisearch_types::error::ResponseError;
|
use meilisearch_types::error::ResponseError;
|
||||||
use meilisearch_types::heed::RoTxn;
|
use meilisearch_types::heed::RoTxn;
|
||||||
@ -233,19 +233,17 @@ async fn document_addition(
|
|||||||
let temp_file = match NamedTempFile::new() {
|
let temp_file = match NamedTempFile::new() {
|
||||||
Ok(temp_file) => temp_file,
|
Ok(temp_file) => temp_file,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("create a temporary file error: {}", e);
|
return Err(MeilisearchHttpError::Payload(ReceivePayloadErr(Box::new(e))));
|
||||||
return Err(MeilisearchHttpError::Payload(ReceivePayloadErr));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
debug!("temp file path: {:?}", temp_file.as_ref());
|
|
||||||
let buffer_file = match temp_file.reopen() {
|
let mut buffer = match File::create(&temp_file.as_ref()).await {
|
||||||
Ok(buffer_file) => buffer_file,
|
Ok(buffer) => buffer,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("reopen payload temporary file error: {}", e);
|
return Err(MeilisearchHttpError::Payload(ReceivePayloadErr(Box::new(e))));
|
||||||
return Err(MeilisearchHttpError::Payload(ReceivePayloadErr));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut buffer = File::from_std(buffer_file);
|
|
||||||
let mut buffer_write_size: usize = 0;
|
let mut buffer_write_size: usize = 0;
|
||||||
while let Some(bytes) = body.next().await {
|
while let Some(bytes) = body.next().await {
|
||||||
let byte = &bytes?;
|
let byte = &bytes?;
|
||||||
@ -257,16 +255,14 @@ async fn document_addition(
|
|||||||
match buffer.write_all(byte).await {
|
match buffer.write_all(byte).await {
|
||||||
Ok(()) => buffer_write_size += 1,
|
Ok(()) => buffer_write_size += 1,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("bufWriter write error: {}", e);
|
return Err(MeilisearchHttpError::Payload(ReceivePayloadErr(Box::new(e))));
|
||||||
return Err(MeilisearchHttpError::Payload(ReceivePayloadErr));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = buffer.flush().await {
|
if let Err(e) = buffer.flush().await {
|
||||||
error!("bufWriter flush error: {}", e);
|
return Err(MeilisearchHttpError::Payload(ReceivePayloadErr(Box::new(e))));
|
||||||
return Err(MeilisearchHttpError::Payload(ReceivePayloadErr));
|
}
|
||||||
};
|
|
||||||
|
|
||||||
if buffer_write_size == 0 {
|
if buffer_write_size == 0 {
|
||||||
return Err(MeilisearchHttpError::MissingPayload(format));
|
return Err(MeilisearchHttpError::MissingPayload(format));
|
||||||
|
Loading…
Reference in New Issue
Block a user