Define From<PreferredUsernameError> for Error

This commit is contained in:
Kitaiti Makoto 2023-01-15 08:57:08 +09:00
parent 39cd4f830d
commit 9bd8f5272f

View File

@ -24,6 +24,7 @@ use heck::ToUpperCamelCase;
pub use lettre; pub use lettre;
pub use lettre::smtp; pub use lettre::smtp;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use plume_common::activity_pub::PreferredUsernameError;
use plume_common::activity_pub::{inbox::InboxError, request, sign, PreferredUsername}; use plume_common::activity_pub::{inbox::InboxError, request, sign, PreferredUsername};
use posts::PostEvent; use posts::PostEvent;
use riker::actors::{channel, ActorSystem, ChannelRef, SystemBuilder}; use riker::actors::{channel, ActorSystem, ChannelRef, SystemBuilder};
@ -175,6 +176,13 @@ impl From<request::Error> for Error {
} }
} }
impl From<PreferredUsernameError> for Error {
fn from(err: PreferredUsernameError) -> Error {
tracing::trace!("{:?}", err);
Error::InvalidValue
}
}
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;
/// Adds a function to a model, that returns the first /// Adds a function to a model, that returns the first
@ -349,13 +357,13 @@ pub enum Fqn {
impl Fqn { impl Fqn {
pub fn new_local(username: String) -> Result<Self> { pub fn new_local(username: String) -> Result<Self> {
Ok(Self::Local( Ok(Self::Local(
PreferredUsername::new(username).map_err(|_| Error::InvalidValue)?, PreferredUsername::new(username)?,
)) ))
} }
pub fn new_remote(username: String, domain: String) -> Result<Self> { pub fn new_remote(username: String, domain: String) -> Result<Self> {
Ok(Self::Remote( Ok(Self::Remote(
PreferredUsername::new(username).map_err(|_| Error::InvalidValue)?, PreferredUsername::new(username)?,
domain, domain,
)) ))
} }