Return empty array instead of error if search for remote profile fails

This commit is contained in:
silverpill 2021-11-07 13:43:20 +00:00
parent aa1ef71857
commit 5cd79eb9b6
3 changed files with 14 additions and 10 deletions

View file

@ -67,6 +67,7 @@ pub async fn fetch_profile(
let webfinger_data = client.get(&webfinger_url)
.query(&[("resource", webfinger_account_uri)])
.send().await?
.error_for_status()?
.text().await?;
let jrd: JsonResourceDescriptor = serde_json::from_str(&webfinger_data)?;
let link = jrd.links.iter()

View file

@ -33,17 +33,19 @@ async fn search_profiles(
if profiles.len() == 0 && instance.is_some() {
let instance_uri = instance.unwrap();
let media_dir = config.media_dir();
let profile_data = fetch_profile(&username, &instance_uri, &media_dir).await
.map_err(|err| {
match fetch_profile(&username, &instance_uri, &media_dir).await {
Ok(profile_data) => {
let profile = create_profile(db_client, &profile_data).await?;
log::info!(
"imported profile '{}'",
profile.acct,
);
profiles.push(profile);
},
Err(err) => {
log::warn!("{}", err);
HttpError::NotFoundError("remote profile")
})?;
let profile = create_profile(db_client, &profile_data).await?;
log::info!(
"imported profile '{}'",
profile.acct,
);
profiles.push(profile);
},
}
}
Ok(profiles)
}

View file

@ -1,3 +1,4 @@
/// https://docs.joinmastodon.org/methods/search/
use actix_web::{get, web, HttpResponse, Scope};
use actix_web_httpauth::extractors::bearer::BearerAuth;