api: Remove {Request,Response}DeserializationError
This commit is contained in:
parent
5a96cbf322
commit
bccbde6f83
@ -1,5 +1,10 @@
|
|||||||
# [unreleased]
|
# [unreleased]
|
||||||
|
|
||||||
|
Breaking changes:
|
||||||
|
|
||||||
|
* Remove the `RequestDeserializationError` and `ResponseDeserializationError`
|
||||||
|
types in favor of using `DeserializationError` directly
|
||||||
|
|
||||||
# 0.18.5
|
# 0.18.5
|
||||||
|
|
||||||
Bug fixes:
|
Bug fixes:
|
||||||
|
@ -47,7 +47,7 @@ impl OutgoingResponse for MatrixError {
|
|||||||
impl EndpointError for MatrixError {
|
impl EndpointError for MatrixError {
|
||||||
fn try_from_http_response<T: AsRef<[u8]>>(
|
fn try_from_http_response<T: AsRef<[u8]>>(
|
||||||
response: http::Response<T>,
|
response: http::Response<T>,
|
||||||
) -> Result<Self, ResponseDeserializationError> {
|
) -> Result<Self, DeserializationError> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
status_code: response.status(),
|
status_code: response.status(),
|
||||||
body: from_json_slice(response.body().as_ref())?,
|
body: from_json_slice(response.body().as_ref())?,
|
||||||
@ -90,7 +90,7 @@ pub enum IntoHttpError {
|
|||||||
pub enum FromHttpRequestError {
|
pub enum FromHttpRequestError {
|
||||||
/// Deserialization failed
|
/// Deserialization failed
|
||||||
#[error("deserialization failed: {0}")]
|
#[error("deserialization failed: {0}")]
|
||||||
Deserialization(RequestDeserializationError),
|
Deserialization(DeserializationError),
|
||||||
|
|
||||||
/// HTTP method mismatch
|
/// HTTP method mismatch
|
||||||
#[error("http method mismatch: expected {expected}, received: {received}")]
|
#[error("http method mismatch: expected {expected}, received: {received}")]
|
||||||
@ -103,27 +103,11 @@ pub enum FromHttpRequestError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T> From<T> for FromHttpRequestError
|
impl<T> From<T> for FromHttpRequestError
|
||||||
where
|
|
||||||
T: Into<RequestDeserializationError>,
|
|
||||||
{
|
|
||||||
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<T> From<T> for RequestDeserializationError
|
|
||||||
where
|
where
|
||||||
T: Into<DeserializationError>,
|
T: Into<DeserializationError>,
|
||||||
{
|
{
|
||||||
fn from(err: T) -> Self {
|
fn from(err: T) -> Self {
|
||||||
Self { inner: err.into() }
|
Self::Deserialization(err.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +116,7 @@ where
|
|||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum FromHttpResponseError<E> {
|
pub enum FromHttpResponseError<E> {
|
||||||
/// Deserialization failed
|
/// Deserialization failed
|
||||||
Deserialization(ResponseDeserializationError),
|
Deserialization(DeserializationError),
|
||||||
|
|
||||||
/// The server returned a non-success status
|
/// The server returned a non-success status
|
||||||
Http(ServerError<E>),
|
Http(ServerError<E>),
|
||||||
@ -155,7 +139,7 @@ impl<E> From<ServerError<E>> for FromHttpResponseError<E> {
|
|||||||
|
|
||||||
impl<E, T> From<T> for FromHttpResponseError<E>
|
impl<E, T> From<T> for FromHttpResponseError<E>
|
||||||
where
|
where
|
||||||
T: Into<ResponseDeserializationError>,
|
T: Into<DeserializationError>,
|
||||||
{
|
{
|
||||||
fn from(err: T) -> Self {
|
fn from(err: T) -> Self {
|
||||||
Self::Deserialization(err.into())
|
Self::Deserialization(err.into())
|
||||||
@ -164,29 +148,6 @@ where
|
|||||||
|
|
||||||
impl<E: StdError> StdError for FromHttpResponseError<E> {}
|
impl<E: StdError> StdError for FromHttpResponseError<E> {}
|
||||||
|
|
||||||
/// An error that occurred when trying to deserialize a response.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ResponseDeserializationError {
|
|
||||||
inner: DeserializationError,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> From<T> for ResponseDeserializationError
|
|
||||||
where
|
|
||||||
T: Into<DeserializationError>,
|
|
||||||
{
|
|
||||||
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)
|
/// An error was reported by the server (HTTP status code 4xx or 5xx)
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[allow(clippy::exhaustive_enums)]
|
#[allow(clippy::exhaustive_enums)]
|
||||||
@ -196,7 +157,7 @@ pub enum ServerError<E> {
|
|||||||
Known(E),
|
Known(E),
|
||||||
|
|
||||||
/// An error of unexpected type of structure
|
/// An error of unexpected type of structure
|
||||||
Unknown(ResponseDeserializationError),
|
Unknown(DeserializationError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: fmt::Display> fmt::Display for ServerError<E> {
|
impl<E: fmt::Display> fmt::Display for ServerError<E> {
|
||||||
|
@ -362,7 +362,7 @@ pub trait EndpointError: OutgoingResponse + StdError + Sized + Send + 'static {
|
|||||||
/// the `ruma_api` macro.
|
/// the `ruma_api` macro.
|
||||||
fn try_from_http_response<T: AsRef<[u8]>>(
|
fn try_from_http_response<T: AsRef<[u8]>>(
|
||||||
response: http::Response<T>,
|
response: http::Response<T>,
|
||||||
) -> Result<Self, error::ResponseDeserializationError>;
|
) -> Result<Self, error::DeserializationError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Marker trait for requests that don't require authentication, for the client side.
|
/// Marker trait for requests that don't require authentication, for the client side.
|
||||||
|
@ -4,7 +4,7 @@ use std::{collections::BTreeMap, fmt, time::Duration};
|
|||||||
|
|
||||||
use bytes::BufMut;
|
use bytes::BufMut;
|
||||||
use ruma_api::{
|
use ruma_api::{
|
||||||
error::{IntoHttpError, ResponseDeserializationError},
|
error::{DeserializationError, IntoHttpError},
|
||||||
EndpointError, OutgoingResponse,
|
EndpointError, OutgoingResponse,
|
||||||
};
|
};
|
||||||
use ruma_identifiers::RoomVersionId;
|
use ruma_identifiers::RoomVersionId;
|
||||||
@ -215,7 +215,7 @@ pub struct Error {
|
|||||||
impl EndpointError for Error {
|
impl EndpointError for Error {
|
||||||
fn try_from_http_response<T: AsRef<[u8]>>(
|
fn try_from_http_response<T: AsRef<[u8]>>(
|
||||||
response: http::Response<T>,
|
response: http::Response<T>,
|
||||||
) -> Result<Self, ResponseDeserializationError> {
|
) -> Result<Self, DeserializationError> {
|
||||||
let status = response.status();
|
let status = response.status();
|
||||||
let error_body: ErrorBody = from_json_slice(response.body().as_ref())?;
|
let error_body: ErrorBody = from_json_slice(response.body().as_ref())?;
|
||||||
Ok(error_body.into_error(status))
|
Ok(error_body.into_error(status))
|
||||||
|
@ -6,7 +6,7 @@ use std::{borrow::Cow, fmt};
|
|||||||
|
|
||||||
use bytes::BufMut;
|
use bytes::BufMut;
|
||||||
use ruma_api::{
|
use ruma_api::{
|
||||||
error::{IntoHttpError, ResponseDeserializationError},
|
error::{DeserializationError, IntoHttpError},
|
||||||
EndpointError, OutgoingResponse,
|
EndpointError, OutgoingResponse,
|
||||||
};
|
};
|
||||||
use ruma_common::thirdparty::Medium;
|
use ruma_common::thirdparty::Medium;
|
||||||
@ -827,7 +827,7 @@ impl From<MatrixError> for UiaaResponse {
|
|||||||
impl EndpointError for UiaaResponse {
|
impl EndpointError for UiaaResponse {
|
||||||
fn try_from_http_response<T: AsRef<[u8]>>(
|
fn try_from_http_response<T: AsRef<[u8]>>(
|
||||||
response: http::Response<T>,
|
response: http::Response<T>,
|
||||||
) -> Result<Self, ResponseDeserializationError> {
|
) -> Result<Self, DeserializationError> {
|
||||||
if response.status() == http::StatusCode::UNAUTHORIZED {
|
if response.status() == http::StatusCode::UNAUTHORIZED {
|
||||||
Ok(UiaaResponse::AuthResponse(from_json_slice(response.body().as_ref())?))
|
Ok(UiaaResponse::AuthResponse(from_json_slice(response.body().as_ref())?))
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user