@@ -59,30 +59,7 @@ pub type HttpResult<T> = std::result::Result<T, HttpError>;
5959
6060/// An error response from a Matrix API call, using a client API specific
6161/// representation if the endpoint is from that.
62- #[ derive( Error , Debug ) ]
63- pub enum RumaApiError {
64- /// A client API response error.
65- #[ error( transparent) ]
66- ClientApi ( ruma:: api:: error:: Error ) ,
67-
68- /// A user-interactive authentication API error.
69- ///
70- /// When registering or authenticating, the Matrix server can send a
71- /// `UiaaInfo` as the error type, this is a User-Interactive Authentication
72- /// API response. This represents an error with information about how to
73- /// authenticate the user.
74- #[ error( "User-Interactive Authentication required." ) ]
75- Uiaa ( UiaaInfo ) ,
76- }
77-
78- impl RumaApiError {
79- /// If `self` is `ClientApi(e)`, returns `Some(e)`.
80- ///
81- /// Otherwise, returns `None`.
82- pub fn as_client_api_error ( & self ) -> Option < & ruma:: api:: error:: Error > {
83- as_variant ! ( self , Self :: ClientApi )
84- }
85- }
62+ pub type RumaApiError = UiaaResponse ;
8663
8764/// An HTTP error, representing either a connection error or an error while
8865/// converting the raw HTTP response into a Matrix response.
@@ -134,35 +111,35 @@ impl HttpError {
134111 _ => None
135112 }
136113 }
137-
138- /// Shorthand for
139- /// <code>.[as_ruma_api_error](Self::as_ruma_api_error)().[and_then](Option::and_then)([RumaApiError::as_client_api_error])</code>.
140- pub fn as_client_api_error ( & self ) -> Option < & ruma:: api:: error:: Error > {
141- self . as_ruma_api_error ( ) . and_then ( RumaApiError :: as_client_api_error)
142- }
143114}
144115
145116// Another impl block that's formatted with rustfmt.
146117impl HttpError {
147118 /// If `self` is a server error in the `errcode` + `error` format expected
148- /// for client-API endpoints, returns the error kind (`errcode`).
119+ /// for client API endpoints, returns it.
120+ pub fn as_client_api_error ( & self ) -> Option < & ruma:: api:: error:: Error > {
121+ self . as_ruma_api_error ( ) . and_then ( as_variant ! ( UiaaResponse :: MatrixError ) )
122+ }
123+
124+ /// If `self` is a server error in the `errcode` + `error` format expected
125+ /// for client API endpoints, returns the error kind (`errcode`).
149126 pub fn client_api_error_kind ( & self ) -> Option < & ErrorKind > {
150127 self . as_client_api_error ( ) . and_then ( ruma:: api:: error:: Error :: error_kind)
151128 }
152129
153- /// Try to destructure the error into an universal interactive auth info.
130+ /// Try to destructure the error into a user- interactive auth info.
154131 ///
155- /// Some requests require universal interactive auth, doing such a request
132+ /// Some requests require user- interactive auth, doing such a request
156133 /// will always fail the first time with a 401 status code, the response
157- /// body will contain info how the client can authenticate.
134+ /// body will contain info on how the client can authenticate.
158135 ///
159136 /// The request will need to be retried, this time containing additional
160137 /// authentication data.
161138 ///
162- /// This method is an convenience method to get to the info the server
139+ /// This method is a convenience method to get to the info the server
163140 /// returned on the first, failed request.
164141 pub fn as_uiaa_response ( & self ) -> Option < & UiaaInfo > {
165- self . as_ruma_api_error ( ) . and_then ( as_variant ! ( RumaApiError :: Uiaa ) )
142+ self . as_ruma_api_error ( ) . and_then ( as_variant ! ( UiaaResponse :: AuthResponse ) )
166143 }
167144
168145 /// Returns whether an HTTP error response should be qualified as transient
@@ -221,16 +198,16 @@ impl RetryKind {
221198 /// format defined in the [spec].
222199 ///
223200 /// [spec]: https://spec.matrix.org/v1.11/client-server-api/#standard-error-response
224- fn from_api_error ( api_error : & RumaApiError ) -> Self {
201+ fn from_api_error ( api_error : & UiaaResponse ) -> Self {
225202 match api_error {
226- RumaApiError :: ClientApi ( client_error) => match client_error. error_kind ( ) {
203+ UiaaResponse :: MatrixError ( client_error) => match client_error. error_kind ( ) {
227204 Some ( ErrorKind :: LimitExceeded ( limit_exceeded) ) => {
228205 RetryKind :: from_retry_after ( limit_exceeded. retry_after . as_ref ( ) )
229206 }
230207 Some ( ErrorKind :: Unrecognized ) => RetryKind :: Permanent ,
231208 _ => RetryKind :: from_status_code ( client_error. status_code ) ,
232209 } ,
233- RumaApiError :: Uiaa ( _) => RetryKind :: Permanent ,
210+ UiaaResponse :: AuthResponse ( _) => RetryKind :: Permanent ,
234211 }
235212 }
236213
@@ -440,14 +417,14 @@ impl Error {
440417 as_variant ! ( self , Self :: Http ) . and_then ( |e| e. as_ruma_api_error ( ) )
441418 }
442419
443- /// Shorthand for
444- /// <code>.[as_ruma_api_error](Self::as_ruma_api_error)().[and_then](Option::and_then)([RumaApiError::as_client_api_error])</code> .
420+ /// If `self` is a server error in the `errcode` + `error` format expected
421+ /// for client API endpoints, returns it .
445422 pub fn as_client_api_error ( & self ) -> Option < & ruma:: api:: error:: Error > {
446- self . as_ruma_api_error ( ) . and_then ( RumaApiError :: as_client_api_error )
423+ self . as_ruma_api_error ( ) . and_then ( as_variant ! ( UiaaResponse :: MatrixError ) )
447424 }
448425
449426 /// If `self` is a server error in the `errcode` + `error` format expected
450- /// for client- API endpoints, returns the error kind (`errcode`).
427+ /// for client API endpoints, returns the error kind (`errcode`).
451428 pub fn client_api_error_kind ( & self ) -> Option < & ErrorKind > {
452429 self . as_client_api_error ( ) . and_then ( ruma:: api:: error:: Error :: error_kind)
453430 }
@@ -464,7 +441,7 @@ impl Error {
464441 /// This method is an convenience method to get to the info the server
465442 /// returned on the first, failed request.
466443 pub fn as_uiaa_response ( & self ) -> Option < & UiaaInfo > {
467- self . as_ruma_api_error ( ) . and_then ( as_variant ! ( RumaApiError :: Uiaa ) )
444+ self . as_ruma_api_error ( ) . and_then ( as_variant ! ( UiaaResponse :: AuthResponse ) )
468445 }
469446}
470447
@@ -586,16 +563,7 @@ pub enum RoomKeyImportError {
586563
587564impl From < FromHttpResponseError < ruma:: api:: error:: Error > > for HttpError {
588565 fn from ( err : FromHttpResponseError < ruma:: api:: error:: Error > ) -> Self {
589- Self :: Api ( Box :: new ( err. map ( RumaApiError :: ClientApi ) ) )
590- }
591- }
592-
593- impl From < FromHttpResponseError < UiaaResponse > > for HttpError {
594- fn from ( err : FromHttpResponseError < UiaaResponse > ) -> Self {
595- Self :: Api ( Box :: new ( err. map ( |e| match e {
596- UiaaResponse :: AuthResponse ( i) => RumaApiError :: Uiaa ( i) ,
597- UiaaResponse :: MatrixError ( e) => RumaApiError :: ClientApi ( e) ,
598- } ) ) )
566+ Self :: Api ( Box :: new ( err. map ( Into :: into) ) )
599567 }
600568}
601569
0 commit comments