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