Propagate new error codes from milli

This commit is contained in:
Louis Dureuil 2022-12-21 12:02:01 +01:00
parent 0e98a71a24
commit b6d80293f7
No known key found for this signature in database
2 changed files with 13 additions and 5 deletions

View File

@ -260,7 +260,7 @@ impl From<v5::ResponseError> for v6::ResponseError {
"invalid_index_uid" => v6::Code::InvalidIndexUid, "invalid_index_uid" => v6::Code::InvalidIndexUid,
"invalid_min_word_length_for_typo" => v6::Code::InvalidMinWordLengthForTypo, "invalid_min_word_length_for_typo" => v6::Code::InvalidMinWordLengthForTypo,
"invalid_state" => v6::Code::InvalidState, "invalid_state" => v6::Code::InvalidState,
"primary_key_inference_failed" => v6::Code::MissingPrimaryKey, "primary_key_inference_failed" => v6::Code::NoPrimaryKeyCandidateFound,
"index_primary_key_already_exists" => v6::Code::PrimaryKeyAlreadyPresent, "index_primary_key_already_exists" => v6::Code::PrimaryKeyAlreadyPresent,
"max_fields_limit_exceeded" => v6::Code::MaxFieldsLimitExceeded, "max_fields_limit_exceeded" => v6::Code::MaxFieldsLimitExceeded,
"missing_document_id" => v6::Code::MissingDocumentId, "missing_document_id" => v6::Code::MissingDocumentId,

View File

@ -126,7 +126,8 @@ pub enum Code {
// invalid state error // invalid state error
InvalidState, InvalidState,
MissingPrimaryKey, NoPrimaryKeyCandidateFound,
MultiplePrimaryKeyCandidatesFound,
PrimaryKeyAlreadyPresent, PrimaryKeyAlreadyPresent,
MaxFieldsLimitExceeded, MaxFieldsLimitExceeded,
@ -211,9 +212,13 @@ impl Code {
// invalid state error // invalid state error
InvalidState => ErrCode::internal("invalid_state", StatusCode::INTERNAL_SERVER_ERROR), InvalidState => ErrCode::internal("invalid_state", StatusCode::INTERNAL_SERVER_ERROR),
// thrown when no primary key has been set // thrown when no primary key has been set
MissingPrimaryKey => { NoPrimaryKeyCandidateFound => {
ErrCode::invalid("primary_key_inference_failed", StatusCode::BAD_REQUEST) ErrCode::invalid("index_primary_key_no_candidate_found", StatusCode::BAD_REQUEST)
} }
MultiplePrimaryKeyCandidatesFound => ErrCode::invalid(
"index_primary_key_multiple_candidates_found",
StatusCode::BAD_REQUEST,
),
// error thrown when trying to set an already existing primary key // error thrown when trying to set an already existing primary key
PrimaryKeyAlreadyPresent => { PrimaryKeyAlreadyPresent => {
ErrCode::invalid("index_primary_key_already_exists", StatusCode::BAD_REQUEST) ErrCode::invalid("index_primary_key_already_exists", StatusCode::BAD_REQUEST)
@ -405,7 +410,10 @@ impl ErrorCode for milli::Error {
UserError::InvalidDocumentId { .. } | UserError::TooManyDocumentIds { .. } => { UserError::InvalidDocumentId { .. } | UserError::TooManyDocumentIds { .. } => {
Code::InvalidDocumentId Code::InvalidDocumentId
} }
UserError::MissingPrimaryKey => Code::MissingPrimaryKey, UserError::NoPrimaryKeyCandidateFound => Code::NoPrimaryKeyCandidateFound,
UserError::MultiplePrimaryKeyCandidatesFound { .. } => {
Code::MultiplePrimaryKeyCandidatesFound
}
UserError::PrimaryKeyCannotBeChanged(_) => Code::PrimaryKeyAlreadyPresent, UserError::PrimaryKeyCannotBeChanged(_) => Code::PrimaryKeyAlreadyPresent,
UserError::SortRankingRuleMissing => Code::Sort, UserError::SortRankingRuleMissing => Code::Sort,
UserError::InvalidFacetsDistribution { .. } => Code::BadRequest, UserError::InvalidFacetsDistribution { .. } => Code::BadRequest,