feat: forward federation errors to the client
This commit is contained in:
parent
1939e62814
commit
e5c7119516
2 changed files with 34 additions and 12 deletions
21
src/error.rs
21
src/error.rs
|
@ -1,5 +1,11 @@
|
|||
use log::{error, warn};
|
||||
use ruma::api::client::{error::ErrorKind, r0::uiaa::UiaaInfo};
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::{Error as RumaError, ErrorKind},
|
||||
r0::uiaa::UiaaInfo,
|
||||
},
|
||||
ServerName,
|
||||
};
|
||||
use thiserror::Error;
|
||||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
|
@ -10,7 +16,7 @@ use {
|
|||
response::{self, Responder},
|
||||
Request,
|
||||
},
|
||||
ruma::api::client::{error::Error as RumaError, r0::uiaa::UiaaResponse},
|
||||
ruma::api::client::r0::uiaa::UiaaResponse,
|
||||
};
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
@ -33,6 +39,8 @@ pub enum Error {
|
|||
source: reqwest::Error,
|
||||
},
|
||||
#[error("{0}")]
|
||||
FederationError(Box<ServerName>, RumaError),
|
||||
#[error("{0}")]
|
||||
BadServerResponse(&'static str),
|
||||
#[error("{0}")]
|
||||
BadConfig(&'static str),
|
||||
|
@ -66,8 +74,13 @@ where
|
|||
'o: 'r,
|
||||
{
|
||||
fn respond_to(self, r: &'r Request<'_>) -> response::Result<'o> {
|
||||
if let Self::Uiaa(uiaainfo) = &self {
|
||||
return RumaResponse::from(UiaaResponse::AuthResponse(uiaainfo.clone())).respond_to(r);
|
||||
if let Self::Uiaa(uiaainfo) = self {
|
||||
return RumaResponse::from(UiaaResponse::AuthResponse(uiaainfo)).respond_to(r);
|
||||
}
|
||||
|
||||
if let Self::FederationError(origin, mut error) = self {
|
||||
error.message = format!("Answer from {}: {}", origin, error.message);
|
||||
return RumaResponse::from(error).respond_to(r);
|
||||
}
|
||||
|
||||
let message = format!("{}", self);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue