From 7bfa622a574c041494ad6140b818e5fb39733db5 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 11 Oct 2022 20:07:21 +0200 Subject: [PATCH] feat(sdk): Add HttpError::as_ruma_api_error --- crates/matrix-sdk/src/error.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/matrix-sdk/src/error.rs b/crates/matrix-sdk/src/error.rs index 9d6111d8f..8133f87d9 100644 --- a/crates/matrix-sdk/src/error.rs +++ b/crates/matrix-sdk/src/error.rs @@ -103,6 +103,18 @@ pub enum HttpError { RefreshToken(#[from] RefreshTokenError), } +impl HttpError { + /// If `self` is `Api(Server(Known(e)))`, returns `Some(e)`. + /// + /// Otherwise, returns `None`. + pub fn as_ruma_api_error(&self) -> Option<&RumaApiError> { + match self { + Self::Api(FromHttpResponseError::Server(ServerError::Known(e))) => Some(e), + _ => None, + } + } +} + /// Internal representation of errors. #[derive(Error, Debug)] #[non_exhaustive]