1use thiserror::Error;
2use tonic::{Code, Status};
3
4#[derive(Error, Debug)]
5pub enum Error {
6 #[error("{0} is not found")]
7 NotFound(String),
8 #[error("{0} already exists")]
9 AlreadyExists(String),
10 #[error("invalid argument: {0}")]
11 InvalidArgument(String),
12}
13
14impl From<Error> for Status {
15 fn from(err: Error) -> Status {
16 let (code, message) = match err {
17 Error::NotFound(m) => (Code::NotFound, m),
18 Error::AlreadyExists(m) => (Code::AlreadyExists, m),
19 Error::InvalidArgument(m) => (Code::InvalidArgument, m),
20 };
21 Status::new(code, message)
22 }
23}
24
25pub type Result<T> = std::result::Result<T, Error>;