mirror of
				https://github.com/meilisearch/meilisearch.git
				synced 2025-10-31 16:06:31 +00:00 
			
		
		
		
	missing payload error
This commit is contained in:
		| @@ -11,9 +11,9 @@ use serde::{Deserialize, Serialize}; | ||||
|  | ||||
| #[derive(Debug, thiserror::Error)] | ||||
| pub enum MeilisearchHttpError { | ||||
|     #[error("A Content-Type header is missing. Accepted values for the Content-Type header are: \"application/json\", \"application/x-ndjson\", \"test/csv\"")] | ||||
|     #[error("A Content-Type header is missing. Accepted values for the Content-Type header are: \"application/json\", \"application/x-ndjson\", \"text/csv\"")] | ||||
|     MissingContentType, | ||||
|     #[error("The Content-Type \"{0}\" is invalid. Accepted values for the Content-Type header are: \"application/json\", \"application/x-ndjson\", \"test/csv\"")] | ||||
|     #[error("The Content-Type \"{0}\" is invalid. Accepted values for the Content-Type header are: \"application/json\", \"application/x-ndjson\", \"text/csv\"")] | ||||
|     InvalidContentType(String), | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -133,13 +133,16 @@ pub async fn add_documents( | ||||
| ) -> Result<HttpResponse, ResponseError> { | ||||
|     debug!("called with params: {:?}", params); | ||||
|     document_addition( | ||||
|         req.headers().get("Content-type").map(|s| s.to_str().unwrap_or("unkown")), | ||||
|         req.headers() | ||||
|             .get("Content-type") | ||||
|             .map(|s| s.to_str().unwrap_or("unkown")), | ||||
|         meilisearch, | ||||
|         path.into_inner().index_uid, | ||||
|         params.into_inner().primary_key, | ||||
|         body, | ||||
|         IndexDocumentsMethod::ReplaceDocuments) | ||||
|         .await | ||||
|         IndexDocumentsMethod::ReplaceDocuments, | ||||
|     ) | ||||
|     .await | ||||
| } | ||||
|  | ||||
| pub async fn update_documents( | ||||
| @@ -151,13 +154,16 @@ pub async fn update_documents( | ||||
| ) -> Result<HttpResponse, ResponseError> { | ||||
|     debug!("called with params: {:?}", params); | ||||
|     document_addition( | ||||
|         req.headers().get("Content-type").map(|s| s.to_str().unwrap_or("unkown")), | ||||
|         req.headers() | ||||
|             .get("Content-type") | ||||
|             .map(|s| s.to_str().unwrap_or("unkown")), | ||||
|         meilisearch, | ||||
|         path.into_inner().index_uid, | ||||
|         params.into_inner().primary_key, | ||||
|         body, | ||||
|         IndexDocumentsMethod::UpdateDocuments) | ||||
|         .await | ||||
|         IndexDocumentsMethod::UpdateDocuments, | ||||
|     ) | ||||
|     .await | ||||
| } | ||||
|  | ||||
| /// Route used when the payload type is "application/json" | ||||
| @@ -174,7 +180,9 @@ async fn document_addition( | ||||
|         Some("application/json") => DocumentAdditionFormat::Json, | ||||
|         Some("application/x-ndjson") => DocumentAdditionFormat::Ndjson, | ||||
|         Some("text/csv") => DocumentAdditionFormat::Csv, | ||||
|         Some(other) => return Err(MeilisearchHttpError::InvalidContentType(other.to_string()).into()), | ||||
|         Some(other) => { | ||||
|             return Err(MeilisearchHttpError::InvalidContentType(other.to_string()).into()) | ||||
|         } | ||||
|         None => return Err(MeilisearchHttpError::MissingContentType.into()), | ||||
|     }; | ||||
|  | ||||
| @@ -185,9 +193,7 @@ async fn document_addition( | ||||
|         format, | ||||
|     }; | ||||
|  | ||||
|     let update_status = meilisearch | ||||
|         .register_update(index_uid, update, true) | ||||
|         .await?; | ||||
|     let update_status = meilisearch.register_update(index_uid, update, true).await?; | ||||
|  | ||||
|     debug!("returns: {:?}", update_status); | ||||
|     Ok(HttpResponse::Accepted().json(serde_json::json!({ "updateId": update_status.id() }))) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user