Small friends fixes (#4270)

* Ensure that fetch errors are properly propagated

* Handle user not found errors better in add_friend

* Cargo fmt

* Introduce new LabrinthError returnable by fetch_advanced

* Allow enter key to send a friend request
This commit is contained in:
Josiah Glosson
2025-08-29 07:08:26 -07:00
committed by GitHub
parent 8b98087936
commit 8fa01b937d
9 changed files with 149 additions and 135 deletions

View File

@@ -1,3 +1,4 @@
use crate::ErrorKind;
use crate::data::ModrinthCredentials;
use crate::event::FriendPayload;
use crate::event::emit::emit_friend;
@@ -322,7 +323,7 @@ impl FriendsSocket {
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite> + Copy,
semaphore: &FetchSemaphore,
) -> crate::Result<()> {
fetch_advanced(
let result = fetch_advanced(
Method::POST,
&format!("{}friend/{user_id}", env!("MODRINTH_API_URL_V3")),
None,
@@ -332,7 +333,18 @@ impl FriendsSocket {
semaphore,
exec,
)
.await?;
.await;
if let Err(ref e) = result
&& let ErrorKind::LabrinthError(e) = &*e.raw
&& e.error == "not_found"
{
return Err(ErrorKind::OtherError(format!(
"No user found with username \"{user_id}\""
))
.into());
}
result?;
Ok(())
}