Propagate database errors returned by importer in search_profiles_or_import()

This commit is contained in:
silverpill 2023-01-11 18:37:39 +00:00
parent 7247441693
commit 22cf00fd98
2 changed files with 28 additions and 18 deletions

View file

@ -12,3 +12,5 @@ pub mod queues;
mod receiver; mod receiver;
pub mod views; pub mod views;
mod vocabulary; mod vocabulary;
pub use receiver::HandlerError;

View file

@ -11,6 +11,7 @@ use crate::activitypub::{
import_profile_by_actor_address, import_profile_by_actor_address,
}, },
identifiers::{parse_local_actor_id, parse_local_object_id}, identifiers::{parse_local_actor_id, parse_local_object_id},
HandlerError,
}; };
use crate::config::Config; use crate::config::Config;
use crate::database::DatabaseError; use crate::database::DatabaseError;
@ -117,11 +118,9 @@ async fn search_profiles_or_import(
maybe_hostname.as_ref(), maybe_hostname.as_ref(),
limit, limit,
).await?; ).await?;
if profiles.is_empty() && maybe_hostname.is_some() { if profiles.is_empty() {
let actor_address = ActorAddress { if let Some(hostname) = maybe_hostname {
username: username, let actor_address = ActorAddress { username, hostname };
hostname: maybe_hostname.unwrap(),
};
match import_profile_by_actor_address( match import_profile_by_actor_address(
db_client, db_client,
&config.instance(), &config.instance(),
@ -131,11 +130,20 @@ async fn search_profiles_or_import(
Ok(profile) => { Ok(profile) => {
profiles.push(profile); profiles.push(profile);
}, },
Err(err) => { Err(HandlerError::DatabaseError(db_error)) => {
log::warn!("{}", err); // Propagate database errors
return Err(db_error);
}, },
} Err(other_error) => {
} log::warn!(
"failed to import profile {}: {}",
actor_address,
other_error,
);
},
};
};
};
Ok(profiles) Ok(profiles)
} }