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:
* 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 `r0::client_exchange::send_event_to_device` (introduced in r0.3.0)
* Add endpoints to retrieve account_data (introduced in r0.5.0)
@ -14,7 +15,7 @@ Improvements:
Breaking changes:
* Update ruma-api to 0.14.0
* Update ruma-api to 0.15.0
* Fix `r0::session::get_login_types`
* Add `allow_remote` parameter to `r0::media::get_content`
* Add missing parameters for `r0::room::create_room`

View File

@ -15,10 +15,10 @@ edition = "2018"
[dependencies]
http = "0.2.0"
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-identifiers = "0.14.1"
serde = { version = "1.0.104", features = ["derive"] }
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"] }

View File

@ -1,5 +1,6 @@
//! Errors that can be sent from the homeserver.
use ruma_api::{error::ResponseDeserializationError, EndpointError};
use serde::{Deserialize, Serialize};
/// An enum for the error kind. Items may contain additional information.
@ -117,6 +118,17 @@ pub struct Error {
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 {
fn from(error: Error) -> Self {
Self {

View File

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

View File

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

View File

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

View File

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

View File

@ -30,4 +30,6 @@ ruma_api! {
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.
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.
pub device_id: DeviceId,
}
error: crate::Error
}
/// The kind of account being registered.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -29,4 +29,6 @@ ruma_api! {
/// Result of unbind operation.
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.
pub user_id: String,
}
error: crate::Error
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -24,4 +24,6 @@ ruma_api! {
}
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.
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.
pub total_room_count_estimate: Option<UInt>,
}
error: crate::Error
}
/// A filter for public rooms lists

View File

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

View File

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

View File

@ -39,4 +39,6 @@ ruma_api! {
/// One-time keys for the queried devices.
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.
pub left: Vec<UserId>
}
error: crate::Error
}

View File

@ -43,4 +43,6 @@ ruma_api! {
/// Information on the queried devices.
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.
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.
pub content_uri: String,
}
error: crate::Error
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -29,4 +29,6 @@ ruma_api! {
/// The room that the user joined.
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.
pub joined: HashMap<UserId, RoomMember>,
}
error: crate::Error
}
// 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.
pub joined_rooms: Vec<RoomId>,
}
error: crate::Error
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -35,6 +35,8 @@ ruma_api! {
#[wrap_incoming]
pub search_categories: ResultCategories,
}
error: crate::Error
}
/// 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.
pub devices: HashMap<String, DeviceInfo>,
}
error: crate::Error
}
/// Information about a connection in a user session.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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