mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-18 21:52:30 -04:00
sdk: use Error::AuthenticationRequired instead of HttpError::AuthenticationRequired
The HttpError variant was misplaced, as it was always used when the `user_id()` is missing, which is causing `Error::AuthenticationRequired` errors everywhere else in the code base. This patch streamlines usage of `Error::AuthenticationRequired`, and gets rid of the `HttpError` variant.
This commit is contained in:
@@ -49,7 +49,7 @@ use ruma::{
|
||||
use serde::Deserialize;
|
||||
use tracing::error;
|
||||
|
||||
use crate::{config::RequestConfig, Client, Error, HttpError, Result};
|
||||
use crate::{config::RequestConfig, Client, Error, Result};
|
||||
|
||||
/// A high-level API to manage the client owner's account.
|
||||
///
|
||||
@@ -741,8 +741,7 @@ impl Account {
|
||||
&self,
|
||||
event_type: GlobalAccountDataEventType,
|
||||
) -> Result<Option<Raw<AnyGlobalAccountDataEventContent>>> {
|
||||
let own_user =
|
||||
self.client.user_id().ok_or_else(|| Error::from(HttpError::AuthenticationRequired))?;
|
||||
let own_user = self.client.user_id().ok_or(Error::AuthenticationRequired)?;
|
||||
|
||||
let request = get_global_account_data::v3::Request::new(own_user.to_owned(), event_type);
|
||||
|
||||
@@ -795,8 +794,7 @@ impl Account {
|
||||
where
|
||||
T: GlobalAccountDataEventContent,
|
||||
{
|
||||
let own_user =
|
||||
self.client.user_id().ok_or_else(|| Error::from(HttpError::AuthenticationRequired))?;
|
||||
let own_user = self.client.user_id().ok_or(Error::AuthenticationRequired)?;
|
||||
|
||||
let request = set_global_account_data::v3::Request::new(own_user.to_owned(), &content)?;
|
||||
|
||||
@@ -809,8 +807,7 @@ impl Account {
|
||||
event_type: GlobalAccountDataEventType,
|
||||
content: Raw<AnyGlobalAccountDataEventContent>,
|
||||
) -> Result<set_global_account_data::v3::Response> {
|
||||
let own_user =
|
||||
self.client.user_id().ok_or_else(|| Error::from(HttpError::AuthenticationRequired))?;
|
||||
let own_user = self.client.user_id().ok_or(Error::AuthenticationRequired)?;
|
||||
|
||||
let request =
|
||||
set_global_account_data::v3::Request::new_raw(own_user.to_owned(), event_type, content);
|
||||
|
||||
@@ -88,11 +88,6 @@ pub enum HttpError {
|
||||
#[error(transparent)]
|
||||
Reqwest(#[from] ReqwestError),
|
||||
|
||||
/// Queried endpoint requires authentication but was called on an anonymous
|
||||
/// client.
|
||||
#[error("the queried endpoint requires authentication but was called before logging in")]
|
||||
AuthenticationRequired,
|
||||
|
||||
/// Queried endpoint is not meant for clients.
|
||||
#[error("the queried endpoint is not meant for clients")]
|
||||
NotClientRequest,
|
||||
|
||||
@@ -104,7 +104,7 @@ use crate::{
|
||||
room::power_levels::{RoomPowerLevelChanges, RoomPowerLevelsExt},
|
||||
sync::RoomUpdate,
|
||||
utils::{IntoRawMessageLikeEventContent, IntoRawStateEventContent},
|
||||
BaseRoom, Client, Error, HttpError, HttpResult, Result, RoomState, TransmissionProgress,
|
||||
BaseRoom, Client, Error, HttpResult, Result, RoomState, TransmissionProgress,
|
||||
};
|
||||
|
||||
pub mod futures;
|
||||
@@ -983,15 +983,15 @@ impl Room {
|
||||
&self,
|
||||
tag: TagName,
|
||||
tag_info: TagInfo,
|
||||
) -> HttpResult<create_tag::v3::Response> {
|
||||
let user_id = self.client.user_id().ok_or(HttpError::AuthenticationRequired)?;
|
||||
) -> Result<create_tag::v3::Response> {
|
||||
let user_id = self.client.user_id().ok_or(Error::AuthenticationRequired)?;
|
||||
let request = create_tag::v3::Request::new(
|
||||
user_id.to_owned(),
|
||||
self.inner.room_id().to_owned(),
|
||||
tag.to_string(),
|
||||
tag_info,
|
||||
);
|
||||
self.client.send(request, None).await
|
||||
Ok(self.client.send(request, None).await?)
|
||||
}
|
||||
|
||||
/// Removes a tag from the room.
|
||||
@@ -1000,14 +1000,14 @@ impl Room {
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `tag` - The tag to remove.
|
||||
pub async fn remove_tag(&self, tag: TagName) -> HttpResult<delete_tag::v3::Response> {
|
||||
let user_id = self.client.user_id().ok_or(HttpError::AuthenticationRequired)?;
|
||||
pub async fn remove_tag(&self, tag: TagName) -> Result<delete_tag::v3::Response> {
|
||||
let user_id = self.client.user_id().ok_or(Error::AuthenticationRequired)?;
|
||||
let request = delete_tag::v3::Request::new(
|
||||
user_id.to_owned(),
|
||||
self.inner.room_id().to_owned(),
|
||||
tag.to_string(),
|
||||
);
|
||||
self.client.send(request, None).await
|
||||
Ok(self.client.send(request, None).await?)
|
||||
}
|
||||
|
||||
/// Add or remove the `m.favourite` flag for this room.
|
||||
@@ -1071,8 +1071,7 @@ impl Room {
|
||||
/// # Arguments
|
||||
/// * `is_direct` - Whether to mark this room as direct.
|
||||
pub async fn set_is_direct(&self, is_direct: bool) -> Result<()> {
|
||||
let user_id =
|
||||
self.client.user_id().ok_or_else(|| Error::from(HttpError::AuthenticationRequired))?;
|
||||
let user_id = self.client.user_id().ok_or(Error::AuthenticationRequired)?;
|
||||
|
||||
let mut content = self
|
||||
.client
|
||||
@@ -2602,8 +2601,7 @@ impl Room {
|
||||
/// Set a flag on the room to indicate that the user has explicitly marked
|
||||
/// it as (un)read.
|
||||
pub async fn set_unread_flag(&self, unread: bool) -> Result<()> {
|
||||
let user_id =
|
||||
self.client.user_id().ok_or_else(|| Error::from(HttpError::AuthenticationRequired))?;
|
||||
let user_id = self.client.user_id().ok_or(Error::AuthenticationRequired)?;
|
||||
|
||||
let content = MarkedUnreadEventContent::new(unread);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user