2020-01-10 18:20:30 +01:00
|
|
|
use std::{error, fmt};
|
|
|
|
|
2020-05-22 12:03:57 +02:00
|
|
|
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),
|
2020-03-09 18:40:49 +01:00
|
|
|
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 {}
|
2020-05-22 12:03:57 +02:00
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
2020-05-22 12:03:57 +02:00
|
|
|
}
|
|
|
|
}
|