feat: forward federation errors to the client

This commit is contained in:
Timo Kösters 2021-05-23 16:45:32 +02:00
parent 1939e62814
commit e5c7119516
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
2 changed files with 34 additions and 12 deletions

View file

@ -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);