From 51b3139c0b023b4e9ba6b82ae5171b16794a0776 Mon Sep 17 00:00:00 2001 From: mpostma Date: Tue, 26 May 2020 13:41:34 +0200 Subject: [PATCH] fix status code --- meilisearch-core/src/database.rs | 2 +- meilisearch-error/src/lib.rs | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/meilisearch-core/src/database.rs b/meilisearch-core/src/database.rs index e01a8a95f..22c7c7d56 100644 --- a/meilisearch-core/src/database.rs +++ b/meilisearch-core/src/database.rs @@ -7,7 +7,7 @@ use std::{fs, thread}; use chrono::{DateTime, Utc}; use crossbeam_channel::{Receiver, Sender}; use heed::types::{Str, Unit, SerdeBincode}; -use heed::{CompactionOption, Result as ZResult}; +use heed::CompactionOption; use log::{debug, error}; use meilisearch_schema::Schema; diff --git a/meilisearch-error/src/lib.rs b/meilisearch-error/src/lib.rs index 158300499..4afe8a46e 100644 --- a/meilisearch-error/src/lib.rs +++ b/meilisearch-error/src/lib.rs @@ -71,7 +71,7 @@ impl Code { // index related errors CreateIndex => ErrCode::invalid("create_index", StatusCode::BAD_REQUEST), IndexAlreadyExists => ErrCode::invalid("existing_index", StatusCode::BAD_REQUEST), - IndexNotFound => ErrCode::invalid("index_not_found", StatusCode::BAD_REQUEST), + IndexNotFound => ErrCode::invalid("index_not_found", StatusCode::NOT_FOUND), InvalidIndexUid => ErrCode::invalid("invalid_index_uid", StatusCode::BAD_REQUEST), OpenIndex => ErrCode::internal("open_index", StatusCode::INTERNAL_SERVER_ERROR), @@ -86,21 +86,21 @@ impl Code { MaxFieldsLimitExceeded => ErrCode::invalid("max_field_limit_exceeded", StatusCode::BAD_REQUEST), Filter => ErrCode::invalid("fitler", StatusCode::BAD_REQUEST), - Facet => ErrCode::invalid("fitler", StatusCode::BAD_REQUEST), + Facet => ErrCode::invalid("facet", StatusCode::BAD_REQUEST), BadParameter => ErrCode::invalid("bad_parameter", StatusCode::BAD_REQUEST), BadRequest => ErrCode::invalid("bad_request", StatusCode::BAD_REQUEST), RetrieveDocument => ErrCode::invalid("retrieve_document", StatusCode::BAD_REQUEST), SearchDocuments => ErrCode::invalid("search_document", StatusCode::BAD_REQUEST), - DocumentNotFound => ErrCode::invalid("document_not_found", StatusCode::BAD_REQUEST), - NotFound => ErrCode::invalid("not_found", StatusCode::BAD_REQUEST), - InvalidToken => ErrCode::invalid("invalid_token", StatusCode::BAD_REQUEST), - MissingHeader => ErrCode::invalid("missing_header", StatusCode::BAD_REQUEST), - MissingAuthorizationHeader => ErrCode::invalid("missing_authorization_header", StatusCode::BAD_REQUEST), - Internal => ErrCode::internal("internal", StatusCode::BAD_REQUEST), - Maintenance => ErrCode::invalid("maintenance", StatusCode::BAD_REQUEST), - PayloadTooLarge => ErrCode::invalid("payload_too_large", StatusCode::BAD_REQUEST), - UnsupportedMediaType => ErrCode::invalid("unsupported_media_type", StatusCode::BAD_REQUEST), + DocumentNotFound => ErrCode::invalid("document_not_found", StatusCode::NOT_FOUND), + NotFound => ErrCode::invalid("not_found", StatusCode::NOT_FOUND), + InvalidToken => ErrCode::authentication("invalid_token", StatusCode::UNAUTHORIZED), + MissingHeader => ErrCode::authentication("missing_header", StatusCode::UNAUTHORIZED), + MissingAuthorizationHeader => ErrCode::authentication("missing_authorization_header", StatusCode::FORBIDDEN), + Internal => ErrCode::internal("internal", StatusCode::INTERNAL_SERVER_ERROR), + Maintenance => ErrCode::invalid("maintenance", StatusCode::SERVICE_UNAVAILABLE), + PayloadTooLarge => ErrCode::invalid("payload_too_large", StatusCode::PAYLOAD_TOO_LARGE), + UnsupportedMediaType => ErrCode::invalid("unsupported_media_type", StatusCode::UNSUPPORTED_MEDIA_TYPE), _ => ErrCode::invalid("other", StatusCode::BAD_REQUEST), } } @@ -119,6 +119,10 @@ impl Code { pub fn r#type(&self) -> String { self.err_code().err_type.to_string() } + + pub fn url(&self) -> String { + format!("docs.meilisearch.come/error/{}", self.name()) + } } /// Internal structure providing a convenient way to create error codes