Simplify a couple lines, forward error on json conversion error

This commit is contained in:
asonix 2020-05-21 20:59:14 -05:00
parent 4b9a8c5354
commit 0fd26a8290

View file

@ -106,9 +106,8 @@ fn single_object(o: &OneOrMany<AnyBase>) -> Result<&AnyBase, MyError> {
} }
async fn handle_accept(config: &Config, input: AcceptedActivities) -> Result<(), MyError> { async fn handle_accept(config: &Config, input: AcceptedActivities) -> Result<(), MyError> {
let follow = if let Ok(Some(follow)) = let base = single_object(input.object())?.clone();
activity::Follow::from_any_base(single_object(input.object())?.clone()) let follow = if let Some(follow) = activity::Follow::from_any_base(base)? {
{
follow follow
} else { } else {
return Err(MyError::Kind( return Err(MyError::Kind(
@ -129,9 +128,8 @@ async fn handle_reject(
input: AcceptedActivities, input: AcceptedActivities,
actor: Actor, actor: Actor,
) -> Result<(), MyError> { ) -> Result<(), MyError> {
let follow = if let Ok(Some(follow)) = let base = single_object(input.object())?.clone();
activity::Follow::from_any_base(single_object(input.object())?.clone()) let follow = if let Some(follow) = activity::Follow::from_any_base(base)? {
{
follow follow
} else { } else {
return Err(MyError::Kind( return Err(MyError::Kind(
@ -140,9 +138,7 @@ async fn handle_reject(
}; };
if !follow.actor_is(&config.generate_url(UrlKind::Actor).parse()?) { if !follow.actor_is(&config.generate_url(UrlKind::Actor).parse()?) {
return Err(MyError::WrongActor( return Err(MyError::WrongActor(id_string(follow.id())?));
follow.id().map(|s| s.to_string()).unwrap_or(String::new()),
));
} }
jobs.queue(Reject(actor))?; jobs.queue(Reject(actor))?;