Require std::error::Error for EndpointError
and implement it for ruma_api::error::FromHttpResponseError and Void. This allows integrating EndpointErrors in the common rust error ecosystem like thiserror and anyhow.
This commit is contained in:
parent
342181ab1a
commit
467e7afd5e
@ -3,6 +3,12 @@
|
|||||||
Breaking changes:
|
Breaking changes:
|
||||||
|
|
||||||
* Update strum dependency to 0.19
|
* Update strum dependency to 0.19
|
||||||
|
* The `EndpointError` trait now requires `std::error::Error`. This allows integrating `EndpointError`s in the common
|
||||||
|
rust error ecosystem like `thiserror` and `anyhow`.
|
||||||
|
|
||||||
|
Improvements:
|
||||||
|
|
||||||
|
* The `EndpointError`s that come with ruma crates now implement `std::errror::Error`.
|
||||||
|
|
||||||
# 0.17.0
|
# 0.17.0
|
||||||
|
|
||||||
|
@ -17,6 +17,14 @@ impl crate::EndpointError for Void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for Void {
|
||||||
|
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for Void {}
|
||||||
|
|
||||||
/// An error when converting one of ruma's endpoint-specific request or response
|
/// An error when converting one of ruma's endpoint-specific request or response
|
||||||
/// types to the corresponding http type.
|
/// types to the corresponding http type.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -162,6 +170,8 @@ impl<E> From<ResponseDeserializationError> for FromHttpResponseError<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<E: std::error::Error> std::error::Error for FromHttpResponseError<E> {}
|
||||||
|
|
||||||
/// An error that occurred when trying to deserialize a response.
|
/// An error that occurred when trying to deserialize a response.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ResponseDeserializationError {
|
pub struct ResponseDeserializationError {
|
||||||
|
@ -232,7 +232,7 @@ pub trait Outgoing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gives users the ability to define their own serializable/deserializable errors.
|
/// Gives users the ability to define their own serializable/deserializable errors.
|
||||||
pub trait EndpointError: Sized {
|
pub trait EndpointError: std::error::Error + Sized {
|
||||||
/// Tries to construct `Self` from an `http::Response`.
|
/// Tries to construct `Self` from an `http::Response`.
|
||||||
///
|
///
|
||||||
/// This will always return `Err` variant when no `error` field is defined in
|
/// This will always return `Err` variant when no `error` field is defined in
|
||||||
|
@ -119,6 +119,8 @@ impl EndpointError for UiaaResponse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for UiaaResponse {}
|
||||||
|
|
||||||
impl From<UiaaResponse> for http::Response<Vec<u8>> {
|
impl From<UiaaResponse> for http::Response<Vec<u8>> {
|
||||||
fn from(uiaa_response: UiaaResponse) -> http::Response<Vec<u8>> {
|
fn from(uiaa_response: UiaaResponse) -> http::Response<Vec<u8>> {
|
||||||
match uiaa_response {
|
match uiaa_response {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user