From d007bf13f1a6a1e65ebb80351dd52b540b451e38 Mon Sep 17 00:00:00 2001 From: mpostma Date: Thu, 4 Jun 2020 14:57:16 +0200 Subject: [PATCH] change missing headers & auth status code --- meilisearch-error/src/lib.rs | 6 ++---- meilisearch-http/src/error.rs | 7 ------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/meilisearch-error/src/lib.rs b/meilisearch-error/src/lib.rs index d9537a9bc..0fbc6a713 100644 --- a/meilisearch-error/src/lib.rs +++ b/meilisearch-error/src/lib.rs @@ -70,7 +70,6 @@ pub enum Code { InvalidToken, Maintenance, MissingAuthorizationHeader, - MissingHeader, NotFound, PayloadTooLarge, RetrieveDocument, @@ -107,10 +106,9 @@ impl Code { BadRequest => ErrCode::invalid("bad_request", StatusCode::BAD_REQUEST), DocumentNotFound => ErrCode::internal("document_not_found", StatusCode::NOT_FOUND), Internal => ErrCode::internal("internal", StatusCode::INTERNAL_SERVER_ERROR), - InvalidToken => ErrCode::authentication("invalid_token", StatusCode::UNAUTHORIZED), + InvalidToken => ErrCode::authentication("invalid_token", StatusCode::FORBIDDEN), Maintenance => ErrCode::internal("maintenance", StatusCode::SERVICE_UNAVAILABLE), - MissingAuthorizationHeader => ErrCode::authentication("missing_authorization_header", StatusCode::FORBIDDEN), - MissingHeader => ErrCode::authentication("missing_header", StatusCode::UNAUTHORIZED), + MissingAuthorizationHeader => ErrCode::authentication("missing_authorization_header", StatusCode::UNAUTHORIZED), NotFound => ErrCode::invalid("not_found", StatusCode::NOT_FOUND), PayloadTooLarge => ErrCode::invalid("payload_too_large", StatusCode::PAYLOAD_TOO_LARGE), RetrieveDocument => ErrCode::internal("retrieve_document", StatusCode::BAD_REQUEST), diff --git a/meilisearch-http/src/error.rs b/meilisearch-http/src/error.rs index 953a5457e..7014b1a5b 100644 --- a/meilisearch-http/src/error.rs +++ b/meilisearch-http/src/error.rs @@ -46,7 +46,6 @@ pub enum Error { InvalidToken(String), Maintenance, MissingAuthorizationHeader, - MissingHeader(String), NotFound(String), OpenIndex(String), RetrieveDocument(u32, String), @@ -71,7 +70,6 @@ impl ErrorCode for Error { InvalidToken(_) => Code::InvalidToken, Maintenance => Code::Maintenance, MissingAuthorizationHeader => Code::MissingAuthorizationHeader, - MissingHeader(_) => Code::MissingHeader, NotFound(_) => Code::NotFound, OpenIndex(_) => Code::OpenIndex, RetrieveDocument(_, _) => Code::RetrieveDocument, @@ -153,10 +151,6 @@ impl Error { Error::DocumentNotFound(err.to_string()) } - pub fn missing_header(err: impl fmt::Display) -> Error { - Error::MissingHeader(err.to_string()) - } - pub fn bad_parameter(param: impl fmt::Display, err: impl fmt::Display) -> Error { Error::BadParameter(param.to_string(), err.to_string()) } @@ -199,7 +193,6 @@ impl fmt::Display for Error { Self::InvalidToken(err) => write!(f, "Invalid API key: {}", err), Self::Maintenance => f.write_str("Server is in maintenance, please try again later"), Self::MissingAuthorizationHeader => f.write_str("You must have an authorization token"), - Self::MissingHeader(header) => write!(f, "Header {} is missing", header), Self::NotFound(err) => write!(f, "{} not found", err), Self::OpenIndex(err) => write!(f, "Impossible to open index; {}", err), Self::RetrieveDocument(id, err) => write!(f, "impossible to retrieve the document with id: {}; {}", id, err),