Browse Source

session: Use accessor to get client api error kind

merge-requests/1327/merge
Kévin Commaille 3 years ago
parent
commit
7154cd1275
No known key found for this signature in database
GPG Key ID: DD507DAE96E8245C
  1. 28
      src/session/account_settings/user_page/change_password_subpage.rs
  2. 29
      src/session/mod.rs
  3. 19
      src/session/room_creation/mod.rs

28
src/session/account_settings/user_page/change_password_subpage.rs

@ -5,18 +5,9 @@ use gtk::{
CompositeTemplate,
};
use log::error;
use matrix_sdk::{
ruma::{
api::{
client::{
account::change_password,
error::{Error as ClientApiError, ErrorBody, ErrorKind},
},
error::FromHttpResponseError,
},
assign,
},
Error as MatrixError, HttpError, RumaApiError,
use matrix_sdk::ruma::{
api::client::{account::change_password, error::ErrorKind},
assign,
};
use crate::{
@ -286,18 +277,7 @@ impl ChangePasswordSubpage {
Err(error) => match error {
AuthError::UserCancelled => {}
AuthError::ServerResponse(error)
if matches!(
error.as_ref(),
MatrixError::Http(HttpError::Api(FromHttpResponseError::Server(
RumaApiError::ClientApi(ClientApiError {
body: ErrorBody::Standard {
kind: ErrorKind::WeakPassword,
..
},
..
},)
)),)
) =>
if matches!(error.client_api_error_kind(), Some(ErrorKind::WeakPassword)) =>
{
error!("Weak password: {error}");
toast!(self, gettext("Password rejected for being too weak"));

29
src/session/mod.rs

@ -26,13 +26,10 @@ use matrix_sdk::{
config::SyncSettings,
room::Room as MatrixRoom,
ruma::{
api::{
client::{
error::{Error as ClientApiError, ErrorBody, ErrorKind},
filter::{FilterDefinition, LazyLoadOptions, RoomEventFilter, RoomFilter},
session::logout,
},
error::FromHttpResponseError,
api::client::{
error::ErrorKind,
filter::{FilterDefinition, LazyLoadOptions, RoomEventFilter, RoomFilter},
session::logout,
},
assign,
events::{
@ -44,7 +41,7 @@ use matrix_sdk::{
RoomId, RoomOrAliasId,
},
sync::SyncResponse,
Client, HttpError, RumaApiError,
Client,
};
use ruma::{api::client::push::get_notifications::v3::Notification, EventId};
use tokio::task::JoinHandle;
@ -661,18 +658,10 @@ impl Session {
}
}
Err(error) => {
if let matrix_sdk::Error::Http(HttpError::Api(FromHttpResponseError::Server(
RumaApiError::ClientApi(ClientApiError {
body:
ErrorBody::Standard {
kind: ErrorKind::UnknownToken { .. },
..
},
..
}),
))) = &error
{
self.handle_logged_out();
if let Some(kind) = error.client_api_error_kind() {
if matches!(kind, ErrorKind::UnknownToken { .. }) {
self.handle_logged_out();
}
}
error!("Failed to perform sync: {error}");
}

19
src/session/room_creation/mod.rs

@ -4,16 +4,13 @@ use gtk::{gdk, glib, glib::clone, CompositeTemplate};
use log::error;
use matrix_sdk::{
ruma::{
api::{
client::{
error::{Error as ClientApiError, ErrorBody, ErrorKind},
room::{create_room, Visibility},
},
error::FromHttpResponseError,
api::client::{
error::ErrorKind,
room::{create_room, Visibility},
},
assign,
},
HttpError, RumaApiError,
HttpError,
};
use ruma::events::{room::encryption::RoomEncryptionEventContent, InitialStateEvent};
@ -227,13 +224,7 @@ impl RoomCreation {
imp.content.set_sensitive(true);
// Handle the room address already taken error.
if let HttpError::Api(FromHttpResponseError::Server(RumaApiError::ClientApi(
ClientApiError {
body: ErrorBody::Standard { kind, .. },
..
},
))) = &error
{
if let Some(kind) = error.client_api_error_kind() {
if *kind == ErrorKind::RoomInUse {
imp.room_address.add_css_class("error");
imp.room_address_error

Loading…
Cancel
Save