impl EndpointError for Error

Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>
This commit is contained in:
Ragotzy.devin 2020-03-21 22:08:08 -04:00 committed by GitHub
parent 122097cfef
commit 1e3769a0f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
117 changed files with 244 additions and 3 deletions

View File

@ -3,6 +3,7 @@
Improvements: Improvements:
* Add an `Error` type that represents the well-known errors in the client-server API * Add an `Error` type that represents the well-known errors in the client-server API
* the response deserialization code will try to create an instance of this type from http responses that indicate an error
* Add OpenID token request endpoint. * Add OpenID token request endpoint.
* Add `r0::client_exchange::send_event_to_device` (introduced in r0.3.0) * Add `r0::client_exchange::send_event_to_device` (introduced in r0.3.0)
* Add endpoints to retrieve account_data (introduced in r0.5.0) * Add endpoints to retrieve account_data (introduced in r0.5.0)
@ -14,7 +15,7 @@ Improvements:
Breaking changes: Breaking changes:
* Update ruma-api to 0.14.0 * Update ruma-api to 0.15.0
* Fix `r0::session::get_login_types` * Fix `r0::session::get_login_types`
* Add `allow_remote` parameter to `r0::media::get_content` * Add `allow_remote` parameter to `r0::media::get_content`
* Add missing parameters for `r0::room::create_room` * Add missing parameters for `r0::room::create_room`

View File

@ -15,10 +15,10 @@ edition = "2018"
[dependencies] [dependencies]
http = "0.2.0" http = "0.2.0"
js_int = { version = "0.1.3", features = ["serde"] } js_int = { version = "0.1.3", features = ["serde"] }
ruma-api = "0.14.0" ruma-api = "0.15.0-dev.1"
ruma-events = "0.17.0" ruma-events = "0.17.0"
ruma-identifiers = "0.14.1" ruma-identifiers = "0.14.1"
serde = { version = "1.0.104", features = ["derive"] } serde = { version = "1.0.104", features = ["derive"] }
serde_json = "1.0.48" serde_json = "1.0.48"
strum = { version = "0.17.1", features = ["derive"] } strum = { version = "0.18.0", features = ["derive"] }
url = { version = "2.1.1", features = ["serde"] } url = { version = "2.1.1", features = ["serde"] }

View File

@ -1,5 +1,6 @@
//! Errors that can be sent from the homeserver. //! Errors that can be sent from the homeserver.
use ruma_api::{error::ResponseDeserializationError, EndpointError};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// An enum for the error kind. Items may contain additional information. /// An enum for the error kind. Items may contain additional information.
@ -117,6 +118,17 @@ pub struct Error {
pub status_code: http::StatusCode, pub status_code: http::StatusCode,
} }
impl EndpointError for Error {
fn try_from_response(
response: http::Response<Vec<u8>>,
) -> Result<Self, ResponseDeserializationError> {
match serde_json::from_slice::<ErrorBody>(response.body()) {
Ok(error_body) => Ok(error_body.into_error(response.status())),
Err(de_error) => Err(ResponseDeserializationError::new(de_error, response)),
}
}
}
impl From<Error> for ErrorBody { impl From<Error> for ErrorBody {
fn from(error: Error) -> Self { fn from(error: Error) -> Self {
Self { Self {

View File

@ -13,3 +13,5 @@ pub mod r0;
pub mod unversioned; pub mod unversioned;
mod serde; mod serde;
pub use error::Error;

View File

@ -26,4 +26,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -22,4 +22,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -28,4 +28,6 @@ ruma_api! {
/// Result of unbind operation. /// Result of unbind operation.
pub id_server_unbind_result: ThirdPartyIdRemovalStatus, pub id_server_unbind_result: ThirdPartyIdRemovalStatus,
} }
error: crate::Error
} }

View File

@ -30,4 +30,6 @@ ruma_api! {
pub id_server_unbind_result: ThirdPartyIdRemovalStatus, pub id_server_unbind_result: ThirdPartyIdRemovalStatus,
} }
error: crate::Error
} }

View File

@ -23,4 +23,6 @@ ruma_api! {
/// This should always be true when the server replies with 200 OK. /// This should always be true when the server replies with 200 OK.
pub available: bool pub available: bool
} }
error: crate::Error
} }

View File

@ -73,6 +73,8 @@ ruma_api! {
/// Will be the same as the corresponding parameter in the request, if one was specified. /// Will be the same as the corresponding parameter in the request, if one was specified.
pub device_id: DeviceId, pub device_id: DeviceId,
} }
error: crate::Error
} }
/// The kind of account being registered. /// The kind of account being registered.

View File

@ -38,4 +38,6 @@ ruma_api! {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub submit_url: Option<String> pub submit_url: Option<String>
} }
error: crate::Error
} }

View File

@ -40,4 +40,6 @@ ruma_api! {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub submit_url: Option<String> pub submit_url: Option<String>
} }
error: crate::Error
} }

View File

@ -33,6 +33,8 @@ ruma_api! {
#[serde(with = "crate::serde::duration::secs")] #[serde(with = "crate::serde::duration::secs")]
pub expires_in: Duration, pub expires_in: Duration,
} }
error: crate::Error
} }
/// Access token types. /// Access token types.

View File

@ -38,4 +38,6 @@ ruma_api! {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub submit_url: Option<String> pub submit_url: Option<String>
} }
error: crate::Error
} }

View File

@ -34,4 +34,6 @@ ruma_api! {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub submit_url: Option<String> pub submit_url: Option<String>
} }
error: crate::Error
} }

View File

@ -38,4 +38,6 @@ ruma_api! {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub submit_url: Option<String> pub submit_url: Option<String>
} }
error: crate::Error
} }

View File

@ -40,4 +40,6 @@ ruma_api! {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub submit_url: Option<String> pub submit_url: Option<String>
} }
error: crate::Error
} }

View File

@ -29,4 +29,6 @@ ruma_api! {
/// Result of unbind operation. /// Result of unbind operation.
pub id_server_unbind_result: ThirdPartyIdRemovalStatus, pub id_server_unbind_result: ThirdPartyIdRemovalStatus,
} }
error: crate::Error
} }

View File

@ -18,4 +18,6 @@ ruma_api! {
/// The id of the user that owns the access token. /// The id of the user that owns the access token.
pub user_id: String, pub user_id: String,
} }
error: crate::Error
} }

View File

@ -22,4 +22,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -20,4 +20,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -25,4 +25,6 @@ ruma_api! {
/// A list of servers that are aware of this room ID. /// A list of servers that are aware of this room ID.
pub servers: Vec<String>, pub servers: Vec<String>,
} }
error: crate::Error
} }

View File

@ -27,4 +27,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -21,6 +21,8 @@ ruma_api! {
/// The capabilities the server supports /// The capabilities the server supports
pub capabilities: Capabilities, pub capabilities: Capabilities,
} }
error: crate::Error
} }
/// Contains information about all the capabilities that the server supports. /// Contains information about all the capabilities that the server supports.

View File

@ -33,4 +33,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -29,4 +29,6 @@ ruma_api! {
#[wrap_incoming(with EventResult)] #[wrap_incoming(with EventResult)]
pub account_data: only::Event, pub account_data: only::Event,
} }
error: crate::Error
} }

View File

@ -32,4 +32,6 @@ ruma_api! {
#[wrap_incoming(with EventResult)] #[wrap_incoming(with EventResult)]
pub account_data: only::Event, pub account_data: only::Event,
} }
error: crate::Error
} }

View File

@ -31,4 +31,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -34,4 +34,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -21,6 +21,8 @@ ruma_api! {
/// account. /// account.
pub threepids: Vec<ThirdPartyIdentifier>, pub threepids: Vec<ThirdPartyIdentifier>,
} }
error: crate::Error
} }
/// An identifier external to Matrix. /// An identifier external to Matrix.

View File

@ -26,4 +26,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -56,4 +56,6 @@ ruma_api! {
#[wrap_incoming(only::StateEvent with EventResult)] #[wrap_incoming(only::StateEvent with EventResult)]
pub state: Vec<only::StateEvent>, pub state: Vec<only::StateEvent>,
} }
error: crate::Error
} }

View File

@ -24,4 +24,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -24,4 +24,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -25,4 +25,6 @@ ruma_api! {
#[ruma_api(body)] #[ruma_api(body)]
pub device: Device, pub device: Device,
} }
error: crate::Error
} }

View File

@ -18,4 +18,6 @@ ruma_api! {
response { response {
devices: Vec<Device>, devices: Vec<Device>,
} }
error: crate::Error
} }

View File

@ -24,4 +24,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -42,4 +42,6 @@ ruma_api! {
/// An estimate on the total number of public rooms, if the server has an estimate. /// An estimate on the total number of public rooms, if the server has an estimate.
pub total_room_count_estimate: Option<UInt>, pub total_room_count_estimate: Option<UInt>,
} }
error: crate::Error
} }

View File

@ -44,6 +44,8 @@ ruma_api! {
/// An estimate on the total number of public rooms, if the server has an estimate. /// An estimate on the total number of public rooms, if the server has an estimate.
pub total_room_count_estimate: Option<UInt>, pub total_room_count_estimate: Option<UInt>,
} }
error: crate::Error
} }
/// A filter for public rooms lists /// A filter for public rooms lists

View File

@ -30,4 +30,6 @@ ruma_api! {
/// The ID of the filter that was created. /// The ID of the filter that was created.
pub filter_id: String, pub filter_id: String,
} }
error: crate::Error
} }

View File

@ -29,4 +29,6 @@ ruma_api! {
#[ruma_api(body)] #[ruma_api(body)]
pub filter: FilterDefinition, pub filter: FilterDefinition,
} }
error: crate::Error
} }

View File

@ -39,4 +39,6 @@ ruma_api! {
/// One-time keys for the queried devices. /// One-time keys for the queried devices.
pub one_time_keys: HashMap<UserId, HashMap<DeviceId, HashMap<AlgorithmAndDeviceId, OneTimeKey>>>, pub one_time_keys: HashMap<UserId, HashMap<DeviceId, HashMap<AlgorithmAndDeviceId, OneTimeKey>>>,
} }
error: crate::Error
} }

View File

@ -33,4 +33,6 @@ ruma_api! {
/// encrypted rooms they previously shared with the user. /// encrypted rooms they previously shared with the user.
pub left: Vec<UserId> pub left: Vec<UserId>
} }
error: crate::Error
} }

View File

@ -43,4 +43,6 @@ ruma_api! {
/// Information on the queried devices. /// Information on the queried devices.
pub device_keys: HashMap<UserId, HashMap<DeviceId, DeviceKeys>>, pub device_keys: HashMap<UserId, HashMap<DeviceId, DeviceKeys>>,
} }
error: crate::Error
} }

View File

@ -32,4 +32,6 @@ ruma_api! {
/// type currently held on the server for this device. /// type currently held on the server for this device.
pub one_time_key_counts: HashMap<KeyAlgorithm, UInt> pub one_time_key_counts: HashMap<KeyAlgorithm, UInt>
} }
error: crate::Error
} }

View File

@ -29,4 +29,6 @@ ruma_api! {
/// The MXC URI for the uploaded content. /// The MXC URI for the uploaded content.
pub content_uri: String, pub content_uri: String,
} }
error: crate::Error
} }

View File

@ -36,4 +36,6 @@ ruma_api! {
#[ruma_api(header = CONTENT_DISPOSITION)] #[ruma_api(header = CONTENT_DISPOSITION)]
pub content_disposition: String, pub content_disposition: String,
} }
error: crate::Error
} }

View File

@ -39,4 +39,6 @@ ruma_api! {
#[ruma_api(header = CONTENT_DISPOSITION)] #[ruma_api(header = CONTENT_DISPOSITION)]
pub content_disposition: String, pub content_disposition: String,
} }
error: crate::Error
} }

View File

@ -57,4 +57,6 @@ ruma_api! {
#[ruma_api(body)] #[ruma_api(body)]
pub file: Vec<u8>, pub file: Vec<u8>,
} }
error: crate::Error
} }

View File

@ -20,4 +20,6 @@ ruma_api! {
#[serde(rename = "m.upload.size")] #[serde(rename = "m.upload.size")]
pub upload_size: UInt, pub upload_size: UInt,
} }
error: crate::Error
} }

View File

@ -31,4 +31,6 @@ ruma_api! {
#[ruma_api(body)] #[ruma_api(body)]
pub data: Option<Value>, pub data: Option<Value>,
} }
error: crate::Error
} }

View File

@ -25,4 +25,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -20,4 +20,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -25,4 +25,6 @@ ruma_api! {
#[wrap_incoming(MemberEvent with EventResult)] #[wrap_incoming(MemberEvent with EventResult)]
pub chunk: Vec<MemberEvent> pub chunk: Vec<MemberEvent>
} }
error: crate::Error
} }

View File

@ -32,6 +32,8 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }
/// Distinguishes between invititations by Matrix or third party identifiers. /// Distinguishes between invititations by Matrix or third party identifiers.

View File

@ -29,4 +29,6 @@ ruma_api! {
/// The room that the user joined. /// The room that the user joined.
pub room_id: RoomId, pub room_id: RoomId,
} }
error: crate::Error
} }

View File

@ -29,4 +29,6 @@ ruma_api! {
/// The room that the user joined. /// The room that the user joined.
pub room_id: RoomId, pub room_id: RoomId,
} }
error: crate::Error
} }

View File

@ -27,6 +27,8 @@ ruma_api! {
/// the ID of each room in which the user has joined membership. /// the ID of each room in which the user has joined membership.
pub joined: HashMap<UserId, RoomMember>, pub joined: HashMap<UserId, RoomMember>,
} }
error: crate::Error
} }
// TODO: Find out whether display_name and avatar_url are optional // TODO: Find out whether display_name and avatar_url are optional

View File

@ -20,4 +20,6 @@ ruma_api! {
/// the ID of each room in which the user has joined membership. /// the ID of each room in which the user has joined membership.
pub joined_rooms: Vec<RoomId>, pub joined_rooms: Vec<RoomId>,
} }
error: crate::Error
} }

View File

@ -25,4 +25,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -20,4 +20,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -22,4 +22,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -38,4 +38,6 @@ ruma_api! {
/// A unique identifier for the event. /// A unique identifier for the event.
pub event_id: EventId, pub event_id: EventId,
} }
error: crate::Error
} }

View File

@ -61,6 +61,8 @@ ruma_api! {
/// The token the pagination ends at. /// The token the pagination ends at.
pub end: String, pub end: String,
} }
error: crate::Error
} }
/// The direction to return events from. /// The direction to return events from.

View File

@ -36,4 +36,6 @@ ruma_api! {
/// The user's presence state. /// The user's presence state.
pub presence: PresenceState, pub presence: PresenceState,
} }
error: crate::Error
} }

View File

@ -26,4 +26,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -24,4 +24,6 @@ ruma_api! {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub avatar_url: Option<String> pub avatar_url: Option<String>
} }
error: crate::Error
} }

View File

@ -24,4 +24,6 @@ ruma_api! {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub displayname: Option<String> pub displayname: Option<String>
} }
error: crate::Error
} }

View File

@ -27,4 +27,6 @@ ruma_api! {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub displayname: Option<String>, pub displayname: Option<String>,
} }
error: crate::Error
} }

View File

@ -22,4 +22,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -23,4 +23,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -29,4 +29,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -47,6 +47,8 @@ ruma_api! {
#[wrap_incoming(Notification)] #[wrap_incoming(Notification)]
pub notifications: Vec<Notification>, pub notifications: Vec<Notification>,
} }
error: crate::Error
} }
/// Represents a notification /// Represents a notification

View File

@ -20,4 +20,6 @@ ruma_api! {
/// An array containing the current pushers for the user. /// An array containing the current pushers for the user.
pub pushers: Vec<Pusher> pub pushers: Vec<Pusher>
} }
error: crate::Error
} }

View File

@ -33,4 +33,6 @@ ruma_api! {
#[ruma_api(body)] #[ruma_api(body)]
pub rule: PushRule pub rule: PushRule
} }
error: crate::Error
} }

View File

@ -32,4 +32,6 @@ ruma_api! {
/// The actions to perform for this rule. /// The actions to perform for this rule.
pub actions: Vec<Action> pub actions: Vec<Action>
} }
error: crate::Error
} }

View File

@ -32,4 +32,6 @@ ruma_api! {
/// Whether the push rule is enabled or not. /// Whether the push rule is enabled or not.
pub enabled: bool pub enabled: bool
} }
error: crate::Error
} }

View File

@ -22,4 +22,6 @@ ruma_api! {
/// The global ruleset /// The global ruleset
pub global: HashMap<RuleKind, Vec<PushRule>> pub global: HashMap<RuleKind, Vec<PushRule>>
} }
error: crate::Error
} }

View File

@ -23,4 +23,6 @@ ruma_api! {
#[ruma_api(body)] #[ruma_api(body)]
pub global: HashMap<RuleKind, Vec<PushRule>>, pub global: HashMap<RuleKind, Vec<PushRule>>,
} }
error: crate::Error
} }

View File

@ -27,4 +27,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -49,4 +49,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -32,4 +32,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -32,4 +32,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -32,4 +32,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -29,6 +29,8 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }
/// The type of receipt. /// The type of receipt.

View File

@ -34,4 +34,6 @@ ruma_api! {
/// The ID of the redacted event. /// The ID of the redacted event.
pub event_id: EventId, pub event_id: EventId,
} }
error: crate::Error
} }

View File

@ -72,6 +72,8 @@ ruma_api! {
/// The created room's ID. /// The created room's ID.
pub room_id: RoomId, pub room_id: RoomId,
} }
error: crate::Error
} }
/// Extra options to be added to the `m.room.create` event. /// Extra options to be added to the `m.room.create` event.

View File

@ -28,4 +28,6 @@ ruma_api! {
#[wrap_incoming(with EventResult)] #[wrap_incoming(with EventResult)]
pub event: all::RoomEvent, pub event: all::RoomEvent,
} }
error: crate::Error
} }

View File

@ -28,4 +28,6 @@ ruma_api! {
} }
response {} response {}
error: crate::Error
} }

View File

@ -25,4 +25,6 @@ ruma_api! {
/// ID of the new room. /// ID of the new room.
pub replacement_room: RoomId, pub replacement_room: RoomId,
} }
error: crate::Error
} }

View File

@ -35,6 +35,8 @@ ruma_api! {
#[wrap_incoming] #[wrap_incoming]
pub search_categories: ResultCategories, pub search_categories: ResultCategories,
} }
error: crate::Error
} }
/// Categories of events that can be searched for. /// Categories of events that can be searched for.

View File

@ -29,6 +29,8 @@ ruma_api! {
/// A map of the user's device identifiers to information about that device. /// A map of the user's device identifiers to information about that device.
pub devices: HashMap<String, DeviceInfo>, pub devices: HashMap<String, DeviceInfo>,
} }
error: crate::Error
} }
/// Information about a connection in a user session. /// Information about a connection in a user session.

View File

@ -19,6 +19,8 @@ ruma_api! {
/// The homeserver's supported login types. /// The homeserver's supported login types.
pub flows: Vec<LoginType> pub flows: Vec<LoginType>
} }
error: crate::Error
} }
/// An authentication mechanism. /// An authentication mechanism.

View File

@ -53,6 +53,8 @@ ruma_api! {
/// If present, clients SHOULD use the provided object to reconfigure themselves. /// If present, clients SHOULD use the provided object to reconfigure themselves.
pub well_known: Option<DiscoveryInfo>, pub well_known: Option<DiscoveryInfo>,
} }
error: crate::Error
} }
/// Identification information for the user. /// Identification information for the user.

View File

@ -15,4 +15,6 @@ ruma_api! {
request {} request {}
response {} response {}
error: crate::Error
} }

View File

@ -15,4 +15,6 @@ ruma_api! {
request {} request {}
response {} response {}
error: crate::Error
} }

View File

@ -25,4 +25,6 @@ ruma_api! {
#[ruma_api(header = LOCATION)] #[ruma_api(header = LOCATION)]
pub location: String, pub location: String,
} }
error: crate::Error
} }

View File

@ -31,4 +31,6 @@ ruma_api! {
/// A unique identifier for the event. /// A unique identifier for the event.
pub event_id: EventId, pub event_id: EventId,
} }
error: crate::Error
} }

View File

@ -34,4 +34,6 @@ ruma_api! {
/// A unique identifier for the event. /// A unique identifier for the event.
pub event_id: EventId, pub event_id: EventId,
} }
error: crate::Error
} }

View File

@ -28,4 +28,6 @@ ruma_api! {
#[wrap_incoming(StateEvent with EventResult)] #[wrap_incoming(StateEvent with EventResult)]
pub room_state: Vec<StateEvent>, pub room_state: Vec<StateEvent>,
} }
error: crate::Error
} }

Some files were not shown because too many files have changed in this diff Show More