return proper error if fail fetching and dont have profile

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-03-04 20:12:45 -05:00 committed by June
parent 465533d32b
commit 9251727d57

View file

@ -116,7 +116,8 @@ pub async fn get_displayname_route(
body: Ruma<get_display_name::v3::Request>,
) -> Result<get_display_name::v3::Response> {
if body.user_id.server_name() != services().globals.server_name() {
let response = services()
// Create and update our local copy of the user
if let Ok(response) = services()
.sending
.send_federation_request(
body.user_id.server_name(),
@ -125,9 +126,8 @@ pub async fn get_displayname_route(
field: None, // we want the full user's profile to update locally too
},
)
.await?;
// Create and update our local copy of the user for only the fields we request for
.await
{
if !services().users.exists(&body.user_id)? {
services().users.create(&body.user_id, None)?;
}
@ -149,6 +149,15 @@ pub async fn get_displayname_route(
displayname: response.displayname,
});
}
}
if !services().users.exists(&body.user_id)? {
// Return 404 if this user doesn't exist and we couldn't fetch it over federation
return Err(Error::BadRequest(
ErrorKind::NotFound,
"Profile was not found.",
));
}
Ok(get_display_name::v3::Response {
displayname: services().users.displayname(&body.user_id)?,
@ -259,7 +268,8 @@ pub async fn get_avatar_url_route(
body: Ruma<get_avatar_url::v3::Request>,
) -> Result<get_avatar_url::v3::Response> {
if body.user_id.server_name() != services().globals.server_name() {
let response = services()
// Create and update our local copy of the user
if let Ok(response) = services()
.sending
.send_federation_request(
body.user_id.server_name(),
@ -268,9 +278,8 @@ pub async fn get_avatar_url_route(
field: None, // we want the full user's profile to update locally as well
},
)
.await?;
// Create and update our local copy of the user
.await
{
if !services().users.exists(&body.user_id)? {
services().users.create(&body.user_id, None)?;
}
@ -293,6 +302,15 @@ pub async fn get_avatar_url_route(
blurhash: response.blurhash,
});
}
}
if !services().users.exists(&body.user_id)? {
// Return 404 if this user doesn't exist and we couldn't fetch it over federation
return Err(Error::BadRequest(
ErrorKind::NotFound,
"Profile was not found.",
));
}
Ok(get_avatar_url::v3::Response {
avatar_url: services().users.avatar_url(&body.user_id)?,
@ -310,7 +328,8 @@ pub async fn get_profile_route(
body: Ruma<get_profile::v3::Request>,
) -> Result<get_profile::v3::Response> {
if body.user_id.server_name() != services().globals.server_name() {
let response = services()
// Create and update our local copy of the user
if let Ok(response) = services()
.sending
.send_federation_request(
body.user_id.server_name(),
@ -319,9 +338,8 @@ pub async fn get_profile_route(
field: None,
},
)
.await?;
// Create and update our local copy of the user
.await
{
if !services().users.exists(&body.user_id)? {
services().users.create(&body.user_id, None)?;
}
@ -345,6 +363,7 @@ pub async fn get_profile_route(
blurhash: response.blurhash,
});
}
}
if !services().users.exists(&body.user_id)? {
// Return 404 if this user doesn't exist and we couldn't fetch it over federation