pub enum ClientError { BadJsonBody(String), BadAuthTokenHeader(String), UserAlreadyExists { username: String }, InvalidPassword, NotAuthorized, } impl ClientError { pub fn kind(&self) -> String { match self { Self::BadJsonBody(..) => "BadJsonBody", Self::BadAuthTokenHeader(..) => "BadAuthTokenHeader", Self::UserAlreadyExists { .. } => "UserAlreadyExists", Self::InvalidPassword => "InvalidPassword", Self::NotAuthorized => "NotAuthorized", } .to_string() } pub fn into_message(self) -> String { match self { Self::BadJsonBody(msg) => msg, Self::BadAuthTokenHeader(msg) => msg, Self::UserAlreadyExists { username } => { format!("user with username `{}` already exists", username) } Self::InvalidPassword => "password is invalid".to_string(), Self::NotAuthorized => "user is not authorized".to_string(), } } }