mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-06 23:15:08 -04:00
refactor(sdk): Reduce the size of Error::Http.
This patch boxes the error in `Error::Http` to reduce the size of this variant (from 160 bytes to 16 bytes).
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
|
||||
//! Error conditions.
|
||||
|
||||
use std::{io::Error as IoError, sync::Arc, time::Duration};
|
||||
use std::{io::Error as IoError, ops::Deref, sync::Arc, time::Duration};
|
||||
|
||||
use as_variant::as_variant;
|
||||
use http::StatusCode;
|
||||
@@ -261,7 +261,7 @@ impl RetryKind {
|
||||
pub enum Error {
|
||||
/// Error doing an HTTP request.
|
||||
#[error(transparent)]
|
||||
Http(#[from] HttpError),
|
||||
Http(Box<HttpError>),
|
||||
|
||||
/// Queried endpoint requires authentication but was called on an anonymous
|
||||
/// client.
|
||||
@@ -431,6 +431,12 @@ impl Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HttpError> for Error {
|
||||
fn from(error: HttpError) -> Self {
|
||||
Error::Http(Box::new(error))
|
||||
}
|
||||
}
|
||||
|
||||
/// Error for the room key importing functionality.
|
||||
#[cfg(feature = "e2e-encryption")]
|
||||
#[derive(Error, Debug)]
|
||||
@@ -505,7 +511,7 @@ impl From<SdkBaseError> for Error {
|
||||
|
||||
impl From<ReqwestError> for Error {
|
||||
fn from(e: ReqwestError) -> Self {
|
||||
Error::Http(HttpError::Reqwest(e))
|
||||
Error::Http(Box::new(HttpError::Reqwest(e)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ impl FromWidgetErrorResponse {
|
||||
/// Create a error response to send to the widget from a matrix sdk error.
|
||||
pub(crate) fn from_error(error: Error) -> Self {
|
||||
match error {
|
||||
Error::Http(e) => FromWidgetErrorResponse::from_http_error(e),
|
||||
Error::Http(e) => FromWidgetErrorResponse::from_http_error(*e),
|
||||
// For UnknownError's we do not want to have the `unknown error` bit in the message.
|
||||
// Hence we only convert the inner error to a string.
|
||||
Error::UnknownError(e) => FromWidgetErrorResponse::from_string(e.to_string()),
|
||||
|
||||
@@ -55,7 +55,11 @@ impl MatrixDriver {
|
||||
/// Requests an OpenID token for the current user.
|
||||
pub(crate) async fn get_open_id(&self) -> Result<OpenIdResponse> {
|
||||
let user_id = self.room.own_user_id().to_owned();
|
||||
self.room.client.send(OpenIdRequest::new(user_id)).await.map_err(Error::Http)
|
||||
self.room
|
||||
.client
|
||||
.send(OpenIdRequest::new(user_id))
|
||||
.await
|
||||
.map_err(|error| Error::Http(Box::new(error)))
|
||||
}
|
||||
|
||||
/// Reads the latest `limit` events of a given `event_type` from the room.
|
||||
@@ -172,7 +176,7 @@ impl MatrixDriver {
|
||||
action: UpdateAction,
|
||||
) -> Result<delayed_events::update_delayed_event::unstable::Response> {
|
||||
let r = delayed_events::update_delayed_event::unstable::Request::new(delay_id, action);
|
||||
self.room.client.send(r).await.map_err(Error::Http)
|
||||
self.room.client.send(r).await.map_err(|error| Error::Http(Box::new(error)))
|
||||
}
|
||||
|
||||
/// Starts forwarding new room events. Once the returned `EventReceiver`
|
||||
|
||||
Reference in New Issue
Block a user