From 7f7b996d240308f59ea363bcb17d45960cea1d40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Mart=C3=ADn?= Date: Thu, 31 Oct 2024 09:05:09 +0100 Subject: [PATCH] refactor(ffi): modify `Client::resolve_room_alias` function Breaking: `ffi::Client::resolve_room_alias` now returns `Result, ClientError>` instead of `Result`. This allows the client to match the 3 possible cases: - The room alias exists. - The room alias does not exist. - The function failed internally. --- bindings/matrix-sdk-ffi/src/client.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index 18bfd4cc8..e822bae7e 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -1027,10 +1027,18 @@ impl Client { pub async fn resolve_room_alias( &self, room_alias: String, - ) -> Result { + ) -> Result, ClientError> { let room_alias = RoomAliasId::parse(&room_alias)?; let response = self.inner.resolve_room_alias(&room_alias).await?; Ok(response.into()) + match self.inner.resolve_room_alias(&room_alias).await { + Ok(response) => Ok(Some(response.into())), + Err(HttpError::Reqwest(http_error)) => match http_error.status() { + Some(StatusCode::NOT_FOUND) => Ok(None), + _ => Err(http_error.into()), + }, + Err(error) => Err(error.into()), + } } /// Given a room id, get the preview of a room, to interact with it.