refactor(sdk): Use ErrorKind for get_state_events_for_key response check

This commit is contained in:
Jonas Platte
2022-11-15 15:25:46 +01:00
committed by Jonas Platte
parent f9d2d32337
commit 5fa6f34e41
2 changed files with 2 additions and 30 deletions

View File

@@ -76,18 +76,6 @@ impl RumaApiError {
_ => None,
}
}
/// Return whether the error was a 404 not found response.
pub fn is_not_found(&self) -> bool {
match self {
RumaApiError::ClientApi(err) => err.status_code == StatusCode::NOT_FOUND,
RumaApiError::Uiaa(UiaaResponse::MatrixError(err)) => {
err.status_code == StatusCode::NOT_FOUND
}
RumaApiError::Uiaa(_) => false,
RumaApiError::Other(err) => err.status_code == StatusCode::NOT_FOUND,
}
}
}
/// An HTTP error, representing either a connection error or an error while
@@ -174,23 +162,6 @@ impl HttpError {
_ => None,
}
}
/// Return whether the error was a 404 not found response.
pub fn is_not_found(&self) -> bool {
match self {
HttpError::Reqwest(err) => err.status() == Some(StatusCode::NOT_FOUND),
HttpError::AuthenticationRequired => false,
HttpError::NotClientRequest => false,
HttpError::Api(FromHttpResponseError::Server(err)) => {
err.is_not_found()
}
HttpError::Api(_) => false,
HttpError::IntoHttp(_) => false,
HttpError::Server(status) => *status == StatusCode::NOT_FOUND,
HttpError::UnableToCloneRequest => false,
HttpError::RefreshToken(_) => false,
}
}
}
/// Internal representation of errors.

View File

@@ -14,6 +14,7 @@ use ruma::events::{
use ruma::{
api::client::{
config::set_global_account_data,
error::ErrorKind,
filter::RoomEventFilter,
membership::{get_member_events, join_room_by_id, leave_room},
message::get_message_events,
@@ -353,7 +354,7 @@ impl Common {
Ok(response) => {
Some(response.content.deserialize_as::<RoomEncryptionEventContent>()?)
}
Err(err) if err.is_not_found() => None,
Err(err) if err.client_api_error_kind() == Some(&ErrorKind::NotFound) => None,
Err(err) => return Err(err.into()),
};