Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More hermes logging #1206

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 63 additions & 23 deletions mutiny-core/src/hermes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ impl<S: MutinyStorage> HermesClient<S> {

// user has a federation registered but is different than current
// so we should update it
log_info!(
logger_check_clone,
"registered federation is different, changing {:?} to {:?}",
o.federation_id,
f.federation_id
);
match change_federation_info(
&http_client_check_clone,
&base_url_check_clone,
Expand All @@ -204,7 +210,12 @@ impl<S: MutinyStorage> HermesClient<S> {
)
.await
{
Ok(_) => (),
Ok(_) => {
log_debug!(
logger_check_clone,
"changed federation successfully"
);
}
Err(e) => {
log_error!(
logger_check_clone,
Expand All @@ -216,6 +227,10 @@ impl<S: MutinyStorage> HermesClient<S> {
// handle the case where the user no longer has a federation
// if user is already disabled, no need to call again
if !o.disabled_zaps {
log_info!(
logger_check_clone,
"user no longer has a federation, disabling zaps"
);
match disable_zaps(
&http_client_check_clone,
&base_url_check_clone,
Expand All @@ -225,7 +240,12 @@ impl<S: MutinyStorage> HermesClient<S> {
)
.await
{
Ok(_) => (),
Ok(_) => {
log_debug!(
logger_check_clone,
"disabled zaps successfully"
);
}
Err(e) => {
log_error!(
logger_check_clone,
Expand Down Expand Up @@ -480,6 +500,10 @@ async fn change_federation_info(
) -> Result<(), MutinyError> {
// make sure name is registered already
if current_address.read().await.0.is_none() {
log_warn!(
logger,
"can't change federation when the address is unknown"
);
return Ok(());
}

Expand All @@ -492,9 +516,12 @@ async fn change_federation_info(
let url = Url::parse(&format!("{}/v1/change-federation", base_url))
.map_err(|_| MutinyError::ConnectionFailed)?;
let request = http_client.request(Method::POST, url).json(&event);
let _ = utils::fetch_with_timeout(http_client, request.build().expect("should build req"))
.await
.map_err(|_| MutinyError::ConnectionFailed)?;
let _ = utils::fetch_with_timeout(
http_client,
request.build().map_err(|_| MutinyError::ConnectionFailed)?,
)
.await
.map_err(|_| MutinyError::ConnectionFailed)?;

log_info!(logger, "changed federation info to current federation");

Expand All @@ -510,6 +537,7 @@ async fn disable_zaps(
) -> Result<(), MutinyError> {
// make sure name is registered already
if current_address.read().await.0.is_none() {
log_warn!(logger, "can't disable zaps when the address is unknown");
return Ok(());
}

Expand All @@ -522,9 +550,12 @@ async fn disable_zaps(
let url = Url::parse(&format!("{}/v1/disable-zaps", base_url))
.map_err(|_| MutinyError::ConnectionFailed)?;
let request = http_client.request(Method::POST, url).json(&event);
let _ = utils::fetch_with_timeout(http_client, request.build().expect("should build req"))
.await
.map_err(|_| MutinyError::ConnectionFailed)?;
let _ = utils::fetch_with_timeout(
http_client,
request.build().map_err(|_| MutinyError::ConnectionFailed)?,
)
.await
.map_err(|_| MutinyError::ConnectionFailed)?;

log_info!(logger, "disabled zaps for the user");

Expand Down Expand Up @@ -562,11 +593,14 @@ async fn check_hermes_registration_info(
let url = Url::parse(&format!("{}/v1/check-registration", base_url))
.map_err(|_| MutinyError::ConnectionFailed)?;
let request = http_client.request(Method::POST, url).json(&event);
let res = utils::fetch_with_timeout(http_client, request.build().expect("should build req"))
.await?
.json::<RegistrationInfo>()
.await
.map_err(|_| MutinyError::ConnectionFailed)?;
let res = utils::fetch_with_timeout(
http_client,
request.build().map_err(|_| MutinyError::ConnectionFailed)?,
)
.await?
.json::<RegistrationInfo>()
.await
.map_err(|_| MutinyError::ConnectionFailed)?;

Ok(res)
}
Expand All @@ -580,11 +614,14 @@ async fn check_name_request(
.map_err(|_| MutinyError::ConnectionFailed)?;
let request = http_client.request(Method::GET, url);

let res = utils::fetch_with_timeout(http_client, request.build().expect("should build req"))
.await?
.json::<bool>()
.await
.map_err(|_| MutinyError::ConnectionFailed)?;
let res = utils::fetch_with_timeout(
http_client,
request.build().map_err(|_| MutinyError::ConnectionFailed)?,
)
.await?
.json::<bool>()
.await
.map_err(|_| MutinyError::ConnectionFailed)?;

Ok(res)
}
Expand All @@ -598,11 +635,14 @@ async fn register_name(
.map_err(|_| MutinyError::ConnectionFailed)?;
let request = http_client.request(Method::POST, url).json(&req);

let res = utils::fetch_with_timeout(http_client, request.build().expect("should build req"))
.await?
.json::<RegisterResponse>()
.await
.map_err(|_| MutinyError::ConnectionFailed)?;
let res = utils::fetch_with_timeout(
http_client,
request.build().map_err(|_| MutinyError::ConnectionFailed)?,
)
.await?
.json::<RegisterResponse>()
.await
.map_err(|_| MutinyError::ConnectionFailed)?;

Ok(res)
}
Expand Down
Loading