From ec97c354e253ef0e3f2bc2ec06faa2c64aa6d75d Mon Sep 17 00:00:00 2001 From: Alexandra <74795488+alyaeanyx@users.noreply.github.com> Date: Wed, 23 Mar 2022 11:57:13 +0100 Subject: [PATCH] feat(sdk): Detect invalid .well-known endpoint response --- crates/matrix-sdk/src/client/builder.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/matrix-sdk/src/client/builder.rs b/crates/matrix-sdk/src/client/builder.rs index 574d083ec..078cd4ffd 100644 --- a/crates/matrix-sdk/src/client/builder.rs +++ b/crates/matrix-sdk/src/client/builder.rs @@ -3,7 +3,11 @@ use std::sync::Arc; use matrix_sdk_base::{locks::RwLock, store::StoreConfig, BaseClient, StateStore}; use ruma::{ api::{ - client::discover::{discover_homeserver, get_supported_versions}, + client::{ + discover::{discover_homeserver, get_supported_versions}, + Error, + }, + error::FromHttpResponseError, MatrixVersion, }, ServerName, UserId, @@ -312,7 +316,11 @@ impl ClientBuilder { None, [MatrixVersion::V1_0].into_iter().collect(), ) - .await?; + .await + .map_err(|e| match e { + HttpError::ClientApi(err) => ClientBuildError::AutoDiscovery(err), + err => ClientBuildError::Http(err), + })?; well_known.homeserver.base_url } @@ -410,6 +418,10 @@ pub enum ClientBuildError { #[error("no homeserver or user ID was configured")] MissingHomeserver, + /// Error looking up the .well-known endpoint on auto-discovery + #[error("Error looking up the .well-known endpoint on auto-discovery")] + AutoDiscovery(FromHttpResponseError), + /// An error encountered when trying to parse the homeserver url. #[error(transparent)] Url(#[from] url::ParseError),