diff --git a/crates/ruma-api/CHANGELOG.md b/crates/ruma-api/CHANGELOG.md index 01c19785..f049d773 100644 --- a/crates/ruma-api/CHANGELOG.md +++ b/crates/ruma-api/CHANGELOG.md @@ -1,5 +1,10 @@ # [unreleased] +Breaking changes: + +* Remove the `RequestDeserializationError` and `ResponseDeserializationError` + types in favor of using `DeserializationError` directly + # 0.18.5 Bug fixes: diff --git a/crates/ruma-api/src/error.rs b/crates/ruma-api/src/error.rs index 4c060c26..eba3a91c 100644 --- a/crates/ruma-api/src/error.rs +++ b/crates/ruma-api/src/error.rs @@ -47,7 +47,7 @@ impl OutgoingResponse for MatrixError { impl EndpointError for MatrixError { fn try_from_http_response>( response: http::Response, - ) -> Result { + ) -> Result { Ok(Self { status_code: response.status(), body: from_json_slice(response.body().as_ref())?, @@ -90,7 +90,7 @@ pub enum IntoHttpError { pub enum FromHttpRequestError { /// Deserialization failed #[error("deserialization failed: {0}")] - Deserialization(RequestDeserializationError), + Deserialization(DeserializationError), /// HTTP method mismatch #[error("http method mismatch: expected {expected}, received: {received}")] @@ -103,27 +103,11 @@ pub enum FromHttpRequestError { } impl From for FromHttpRequestError -where - T: Into, -{ - fn from(err: T) -> Self { - Self::Deserialization(err.into()) - } -} - -/// An error that occurred when trying to deserialize a request. -#[derive(Debug, Error)] -#[error("{inner}")] -pub struct RequestDeserializationError { - inner: DeserializationError, -} - -impl From for RequestDeserializationError where T: Into, { fn from(err: T) -> Self { - Self { inner: err.into() } + Self::Deserialization(err.into()) } } @@ -132,7 +116,7 @@ where #[non_exhaustive] pub enum FromHttpResponseError { /// Deserialization failed - Deserialization(ResponseDeserializationError), + Deserialization(DeserializationError), /// The server returned a non-success status Http(ServerError), @@ -155,7 +139,7 @@ impl From> for FromHttpResponseError { impl From for FromHttpResponseError where - T: Into, + T: Into, { fn from(err: T) -> Self { Self::Deserialization(err.into()) @@ -164,29 +148,6 @@ where impl StdError for FromHttpResponseError {} -/// An error that occurred when trying to deserialize a response. -#[derive(Debug)] -pub struct ResponseDeserializationError { - inner: DeserializationError, -} - -impl From for ResponseDeserializationError -where - T: Into, -{ - fn from(err: T) -> Self { - Self { inner: err.into() } - } -} - -impl fmt::Display for ResponseDeserializationError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Display::fmt(&self.inner, f) - } -} - -impl StdError for ResponseDeserializationError {} - /// An error was reported by the server (HTTP status code 4xx or 5xx) #[derive(Debug)] #[allow(clippy::exhaustive_enums)] @@ -196,7 +157,7 @@ pub enum ServerError { Known(E), /// An error of unexpected type of structure - Unknown(ResponseDeserializationError), + Unknown(DeserializationError), } impl fmt::Display for ServerError { diff --git a/crates/ruma-api/src/lib.rs b/crates/ruma-api/src/lib.rs index 85e191c4..211b4141 100644 --- a/crates/ruma-api/src/lib.rs +++ b/crates/ruma-api/src/lib.rs @@ -362,7 +362,7 @@ pub trait EndpointError: OutgoingResponse + StdError + Sized + Send + 'static { /// the `ruma_api` macro. fn try_from_http_response>( response: http::Response, - ) -> Result; + ) -> Result; } /// Marker trait for requests that don't require authentication, for the client side. diff --git a/crates/ruma-client-api/src/error.rs b/crates/ruma-client-api/src/error.rs index bcbfb518..8370f8e7 100644 --- a/crates/ruma-client-api/src/error.rs +++ b/crates/ruma-client-api/src/error.rs @@ -4,7 +4,7 @@ use std::{collections::BTreeMap, fmt, time::Duration}; use bytes::BufMut; use ruma_api::{ - error::{IntoHttpError, ResponseDeserializationError}, + error::{DeserializationError, IntoHttpError}, EndpointError, OutgoingResponse, }; use ruma_identifiers::RoomVersionId; @@ -215,7 +215,7 @@ pub struct Error { impl EndpointError for Error { fn try_from_http_response>( response: http::Response, - ) -> Result { + ) -> Result { let status = response.status(); let error_body: ErrorBody = from_json_slice(response.body().as_ref())?; Ok(error_body.into_error(status)) diff --git a/crates/ruma-client-api/src/r0/uiaa.rs b/crates/ruma-client-api/src/r0/uiaa.rs index 92ce8b3e..f9ce3646 100644 --- a/crates/ruma-client-api/src/r0/uiaa.rs +++ b/crates/ruma-client-api/src/r0/uiaa.rs @@ -6,7 +6,7 @@ use std::{borrow::Cow, fmt}; use bytes::BufMut; use ruma_api::{ - error::{IntoHttpError, ResponseDeserializationError}, + error::{DeserializationError, IntoHttpError}, EndpointError, OutgoingResponse, }; use ruma_common::thirdparty::Medium; @@ -827,7 +827,7 @@ impl From for UiaaResponse { impl EndpointError for UiaaResponse { fn try_from_http_response>( response: http::Response, - ) -> Result { + ) -> Result { if response.status() == http::StatusCode::UNAUTHORIZED { Ok(UiaaResponse::AuthResponse(from_json_slice(response.body().as_ref())?)) } else {