refactor Error::bad_config
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
93ec4e579b
commit
4cc92dd175
10 changed files with 71 additions and 66 deletions
|
@ -7,7 +7,7 @@ use std::{
|
|||
time::Duration,
|
||||
};
|
||||
|
||||
use conduit::{error, Config, Error, Result};
|
||||
use conduit::{error, Config, Result};
|
||||
use hickory_resolver::TokioAsyncResolver;
|
||||
use reqwest::dns::{Addrs, Name, Resolve, Resolving};
|
||||
use ruma::OwnedServerName;
|
||||
|
@ -33,10 +33,7 @@ impl Resolver {
|
|||
#[allow(clippy::as_conversions, clippy::cast_sign_loss, clippy::cast_possible_truncation)]
|
||||
pub(super) fn new(config: &Config) -> Self {
|
||||
let (sys_conf, mut opts) = hickory_resolver::system_conf::read_system_conf()
|
||||
.map_err(|e| {
|
||||
error!("Failed to set up hickory dns resolver with system config: {e}");
|
||||
Error::bad_config("Failed to set up hickory dns resolver with system config.")
|
||||
})
|
||||
.inspect_err(|e| error!("Failed to set up hickory dns resolver with system config: {e}"))
|
||||
.expect("DNS system config must be valid");
|
||||
|
||||
let mut conf = hickory_resolver::config::ResolverConfig::new();
|
||||
|
|
|
@ -3,7 +3,7 @@ mod remote;
|
|||
|
||||
use std::sync::Arc;
|
||||
|
||||
use conduit::{Error, Result};
|
||||
use conduit::{err, Error, Result};
|
||||
use data::Data;
|
||||
use ruma::{
|
||||
api::{appservice, client::error::ErrorKind},
|
||||
|
@ -171,7 +171,7 @@ impl Service {
|
|||
.rooms
|
||||
.alias
|
||||
.resolve_local_alias(room_alias)?
|
||||
.ok_or_else(|| Error::bad_config("Room does not exist."))?,
|
||||
.ok_or_else(|| err!(BadConfig("Room does not exist.")))?,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ use std::{
|
|||
time::SystemTime,
|
||||
};
|
||||
|
||||
use conduit::Err;
|
||||
use hickory_resolver::{error::ResolveError, lookup::SrvLookup};
|
||||
use ipaddress::IPAddress;
|
||||
use ruma::{OwnedServerName, ServerName};
|
||||
|
@ -354,7 +355,7 @@ fn handle_resolve_error(e: &ResolveError) -> Result<()> {
|
|||
|
||||
fn validate_dest(dest: &ServerName) -> Result<()> {
|
||||
if dest == services().globals.server_name() {
|
||||
return Err(Error::bad_config("Won't send federation request to ourselves"));
|
||||
return Err!("Won't send federation request to ourselves");
|
||||
}
|
||||
|
||||
if dest.is_ip_literal() || IPAddress::is_valid(dest.host()) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use std::{fmt::Debug, mem};
|
||||
|
||||
use conduit::Err;
|
||||
use http::{header::AUTHORIZATION, HeaderValue};
|
||||
use ipaddress::IPAddress;
|
||||
use reqwest::{Client, Method, Request, Response, Url};
|
||||
|
@ -26,7 +27,7 @@ where
|
|||
T: OutgoingRequest + Debug + Send,
|
||||
{
|
||||
if !services().globals.allow_federation() {
|
||||
return Err(Error::bad_config("Federation is disabled."));
|
||||
return Err!(Config("allow_federation", "Federation is disabled."));
|
||||
}
|
||||
|
||||
let actual = resolve::get_actual_dest(dest).await?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue