use geoffrey_models::models::response::api_error::GeoffreyAPIError; pub type Result = std::result::Result; #[derive(Debug)] pub enum GeoffreyDBError { SledError(sled::Error), SerdeJsonError(serde_json::Error), NotUnique, NotFound, } impl std::error::Error for GeoffreyDBError {} impl std::fmt::Display for GeoffreyDBError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { GeoffreyDBError::SledError(e) => write!(f, "Sled Error: {}", e), GeoffreyDBError::SerdeJsonError(e) => write!(f, "Serde JSON Error: {}", e), GeoffreyDBError::NotUnique => write!(f, "Entry is not unique."), GeoffreyDBError::NotFound => write!(f, "Entry was not found."), } } } impl From for GeoffreyDBError { fn from(e: sled::Error) -> Self { GeoffreyDBError::SledError(e) } } impl From for GeoffreyDBError { fn from(e: serde_json::Error) -> Self { GeoffreyDBError::SerdeJsonError(e) } } impl Into for GeoffreyDBError { fn into(self) -> GeoffreyAPIError { match self { GeoffreyDBError::SledError(_) => GeoffreyAPIError::DatabaseError(self.to_string()), GeoffreyDBError::SerdeJsonError(_) => GeoffreyAPIError::DatabaseError(self.to_string()), GeoffreyDBError::NotUnique => GeoffreyAPIError::EntryNotUnique, GeoffreyDBError::NotFound => GeoffreyAPIError::EntryNotFound } } }