mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 06:44:27 +01:00
empty content type error
This commit is contained in:
parent
e400ae900d
commit
137272b8de
@ -83,6 +83,8 @@ pub enum Code {
|
|||||||
|
|
||||||
DumpAlreadyInProgress,
|
DumpAlreadyInProgress,
|
||||||
DumpProcessFailed,
|
DumpProcessFailed,
|
||||||
|
|
||||||
|
MissingContentType,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Code {
|
impl Code {
|
||||||
@ -154,6 +156,7 @@ impl Code {
|
|||||||
DumpProcessFailed => {
|
DumpProcessFailed => {
|
||||||
ErrCode::internal("dump_process_failed", StatusCode::INTERNAL_SERVER_ERROR)
|
ErrCode::internal("dump_process_failed", StatusCode::INTERNAL_SERVER_ERROR)
|
||||||
}
|
}
|
||||||
|
MissingContentType => ErrCode::invalid("missing_content_type", StatusCode::UNSUPPORTED_MEDIA_TYPE),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,20 @@ use aweb::error::{JsonPayloadError, QueryPayloadError};
|
|||||||
use meilisearch_error::{Code, ErrorCode};
|
use meilisearch_error::{Code, ErrorCode};
|
||||||
use serde::{Deserialize, Serialize};
|
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\"")]
|
||||||
|
MissingContentType,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ErrorCode for MeilisearchHttpError {
|
||||||
|
fn error_code(&self) -> Code {
|
||||||
|
match self {
|
||||||
|
MeilisearchHttpError::MissingContentType => Code::MissingContentType,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct ResponseError {
|
pub struct ResponseError {
|
||||||
|
@ -10,7 +10,7 @@ use serde::Deserialize;
|
|||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
use crate::error::ResponseError;
|
use crate::error::{MeilisearchHttpError, ResponseError};
|
||||||
use crate::extractors::authentication::{policies::*, GuardedData};
|
use crate::extractors::authentication::{policies::*, GuardedData};
|
||||||
use crate::extractors::payload::Payload;
|
use crate::extractors::payload::Payload;
|
||||||
use crate::routes::IndexParam;
|
use crate::routes::IndexParam;
|
||||||
@ -66,7 +66,7 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
|
|||||||
.route(
|
.route(
|
||||||
web::post()
|
web::post()
|
||||||
.guard(empty_application_type)
|
.guard(empty_application_type)
|
||||||
.to(HttpResponse::UnsupportedMediaType),
|
.to(missing_content_type_error),
|
||||||
)
|
)
|
||||||
.route(web::post().guard(guard_json).to(add_documents_json))
|
.route(web::post().guard(guard_json).to(add_documents_json))
|
||||||
.route(web::post().guard(guard_ndjson).to(add_documents_ndjson))
|
.route(web::post().guard(guard_ndjson).to(add_documents_ndjson))
|
||||||
@ -76,7 +76,7 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
|
|||||||
.route(
|
.route(
|
||||||
web::put()
|
web::put()
|
||||||
.guard(empty_application_type)
|
.guard(empty_application_type)
|
||||||
.to(HttpResponse::UnsupportedMediaType),
|
.to(missing_content_type_error),
|
||||||
)
|
)
|
||||||
.route(web::put().guard(guard_json).to(update_documents_json))
|
.route(web::put().guard(guard_json).to(update_documents_json))
|
||||||
.route(web::put().guard(guard_ndjson).to(update_documents_ndjson))
|
.route(web::put().guard(guard_ndjson).to(update_documents_ndjson))
|
||||||
@ -93,6 +93,10 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn missing_content_type_error() -> Result<HttpResponse, ResponseError> {
|
||||||
|
Err(MeilisearchHttpError::MissingContentType.into())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_document(
|
pub async fn get_document(
|
||||||
meilisearch: GuardedData<Public, MeiliSearch>,
|
meilisearch: GuardedData<Public, MeiliSearch>,
|
||||||
path: web::Path<DocumentParam>,
|
path: web::Path<DocumentParam>,
|
||||||
|
Loading…
Reference in New Issue
Block a user