feat(sdk): Add HttpError::as_ruma_api_error

This commit is contained in:
Jonas Platte
2022-10-11 20:07:21 +02:00
committed by Jonas Platte
parent f4e0cab11f
commit 7bfa622a57
+12
View File
@@ -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]