diff --git a/meilisearch-error/src/lib.rs b/meilisearch-error/src/lib.rs index 05c0ebb77..158300499 100644 --- a/meilisearch-error/src/lib.rs +++ b/meilisearch-error/src/lib.rs @@ -36,6 +36,7 @@ pub enum Code { // invalid state error InvalidState, MissingPrimaryKey, + PrimaryKeyAlreadyPresent, // invalid documents FIXME make one error code? MissingDocumentId, @@ -77,7 +78,8 @@ impl Code { // invalid state error InvalidState => ErrCode::internal("invalid_state", StatusCode::INTERNAL_SERVER_ERROR), // FIXME probably not an internal statuscode there - MissingPrimaryKey => ErrCode::internal("MissingPrimaryKey", StatusCode::INTERNAL_SERVER_ERROR), + MissingPrimaryKey => ErrCode::internal("missing_primary_key", StatusCode::INTERNAL_SERVER_ERROR), + PrimaryKeyAlreadyPresent => ErrCode::internal("primary_key_already_present", StatusCode::INTERNAL_SERVER_ERROR), // invalid document MissingDocumentId => ErrCode::invalid("MissingDocumentId", StatusCode::BAD_REQUEST), diff --git a/meilisearch-schema/src/error.rs b/meilisearch-schema/src/error.rs index 84c908596..8dcc0a7a4 100644 --- a/meilisearch-schema/src/error.rs +++ b/meilisearch-schema/src/error.rs @@ -26,7 +26,12 @@ impl error::Error for Error {} impl ErrorCode for Error { fn error_code(&self) -> Code { - // TODO populate with correct error codes - Code::Internal + use Error::*; + + match self { + FieldNameNotFound(_) => Code::Internal, + MaxFieldsLimitExceeded => Code::MaxFieldsLimitExceeded, + PrimaryKeyAlreadyPresent => Code::PrimaryKeyAlreadyPresent, + } } }