enhance error handling

This commit is contained in:
刘瀚骋 2021-09-16 17:56:18 +08:00
parent 8748df2ca4
commit 50ad750ec1
2 changed files with 127 additions and 123 deletions

View file

@ -64,6 +64,7 @@ pub enum UserError {
InvalidGeoField { document_id: Value, object: Value },
InvalidFilterAttributeNom,
InvalidFilterValue,
InvalidFilterNom { input: String },
InvalidSortName { name: String },
InvalidSortableAttribute { field: String, valid_fields: HashSet<String> },
SortRankingRuleMissing,
@ -85,11 +86,6 @@ impl From<io::Error> for Error {
Error::IoError(error)
}
}
impl From<std::num::ParseFloatError> for UserError {
fn from(_: std::num::ParseFloatError) -> UserError {
UserError::InvalidFilterValue
}
}
impl From<fst::Error> for Error {
fn from(error: fst::Error) -> Error {
@ -217,8 +213,7 @@ impl fmt::Display for UserError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
//TODO
Self::InvalidFilterAttributeNom => f.write_str("parser error "),
Self::InvalidFilterValue => f.write_str("parser error "),
Self::InvalidFilterNom { input } => write!(f, "parser error {}", input),
Self::AttributeLimitReached => f.write_str("maximum number of attributes reached"),
Self::CriterionError(error) => write!(f, "{}", error),
Self::DocumentLimitReached => f.write_str("maximum number of documents reached"),