From 5fa6f34e416e45c93ff6e6516013fe9fd8dcd890 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 15 Nov 2022 15:25:46 +0100 Subject: [PATCH] refactor(sdk): Use ErrorKind for get_state_events_for_key response check --- crates/matrix-sdk/src/error.rs | 29 ---------------------------- crates/matrix-sdk/src/room/common.rs | 3 ++- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/crates/matrix-sdk/src/error.rs b/crates/matrix-sdk/src/error.rs index 3355e6372..dea936e9e 100644 --- a/crates/matrix-sdk/src/error.rs +++ b/crates/matrix-sdk/src/error.rs @@ -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. diff --git a/crates/matrix-sdk/src/room/common.rs b/crates/matrix-sdk/src/room/common.rs index cb3900b0a..34bbf1c28 100644 --- a/crates/matrix-sdk/src/room/common.rs +++ b/crates/matrix-sdk/src/room/common.rs @@ -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::()?) } - 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()), };