MeiliSearch/meilisearch-schema/src/error.rs

38 lines
1.0 KiB
Rust
Raw Normal View History

2020-01-10 18:20:30 +01:00
use std::{error, fmt};
use meilisearch_error::{ErrorCode, Code};
2020-01-10 18:20:30 +01:00
pub type SResult<T> = Result<T, Error>;
#[derive(Debug)]
pub enum Error {
2020-01-13 19:10:58 +01:00
FieldNameNotFound(String),
PrimaryKeyAlreadyPresent,
2020-01-10 18:20:30 +01:00
MaxFieldsLimitExceeded,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::Error::*;
match self {
2020-01-29 18:30:21 +01:00
FieldNameNotFound(field) => write!(f, "The field {:?} doesn't exist", field),
2020-07-28 15:18:05 +02:00
PrimaryKeyAlreadyPresent => write!(f, "A primary key is already present. It's impossible to update it"),
2020-01-29 18:30:21 +01:00
MaxFieldsLimitExceeded => write!(f, "The maximum of possible reattributed field id has been reached"),
2020-01-10 18:20:30 +01:00
}
}
}
impl error::Error for Error {}
impl ErrorCode for Error {
fn error_code(&self) -> Code {
2020-05-26 12:17:53 +02:00
use Error::*;
match self {
FieldNameNotFound(_) => Code::Internal,
MaxFieldsLimitExceeded => Code::MaxFieldsLimitExceeded,
PrimaryKeyAlreadyPresent => Code::PrimaryKeyAlreadyPresent,
}
}
}