Skip to content
Draft
Show file tree
Hide file tree
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
12 changes: 9 additions & 3 deletions apps/auth-service/src/admin/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,16 @@ impl From<AdminError> for ApiError {
| AdminError::HandleReserved
| AdminError::AnnouncementSent
| AdminError::AnnouncementChanged
| AdminError::SigningKey(KeyError::Mismatched(_) | KeyError::NoActiveKey) => {
Self::conflict(message)
}
// A stored key that cannot sign is refused, and the form says which.
| AdminError::SigningKey(
KeyError::Stored { .. } | KeyError::Mismatched(_) | KeyError::NoActiveKey,
) => Self::conflict(message),
// Why it cannot, such as a key-encryption key no longer accepted, is
// only for the log.
error @ AdminError::SigningKey(KeyError::Stored { .. }) => {
Self::log_error(&error);
Self::conflict(message)
}
AdminError::Database(error) | AdminError::SigningKey(KeyError::Database(error)) => {
error.into()
}
Expand Down
50 changes: 39 additions & 11 deletions apps/auth-service/src/deliveries/outbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use reqwest::{
dns::{Addrs, Name, Resolve, Resolving},
redirect,
};
use sourceorigin_common::net::PublicAddress;
use sourceorigin_common::{ErrorChain, net::PublicAddress};
use sourceorigin_telemetry::SendTraced;
use std::{
error::Error as StdError,
Expand All @@ -22,6 +22,7 @@ use std::{
time::Duration,
};
use thiserror::Error;
use tracing::Level;
use url::{Host, Url};

/// The longest connecting to a destination may take.
Expand Down Expand Up @@ -100,7 +101,11 @@ impl OutboundClient {
destination: &str,
request: impl FnOnce(RequestBuilder) -> RequestBuilder,
) -> Result<(), DeliveryError> {
self.request(method, destination, request).await.map(drop)
// A delivery's worker logs only the failure, so the cause is a warning
// beside it.
self.request(method, destination, request, Level::WARN)
.await
.map(drop)
}

/// Fetches `destination` with `GET`, as [`Self::send`] sends, asking for the
Expand All @@ -117,36 +122,43 @@ impl OutboundClient {
accept: &str,
limit: usize,
) -> Result<Vec<u8>, DeliveryError> {
// The caller warns of the failure, so the cause is only for debugging.
let cause = Level::DEBUG;
let mut response = self
.request(Method::GET, destination, |request| {
request.header(ACCEPT, accept)
})
.request(
Method::GET,
destination,
|request| request.header(ACCEPT, accept),
cause,
)
.await?;
let mut body = Vec::new();
while body.len() < limit
&& let Some(chunk) = response
.chunk()
.await
.map_err(|error| Self::transport_error(&error))?
.map_err(|error| Self::transport_error(error, cause))?
{
let room = limit - body.len();
body.extend_from_slice(&chunk[..chunk.len().min(room)]);
}
Ok(body)
}

/// [`Self::send`], returning the successful response with its body unread.
/// [`Self::send`], returning the successful response with its body unread,
/// and logging a transport failure's cause at `cause`.
async fn request(
&self,
method: Method,
destination: &str,
request: impl FnOnce(RequestBuilder) -> RequestBuilder,
cause: Level,
) -> Result<reqwest::Response, DeliveryError> {
let url = self.check(destination)?;
let response = request(self.client.request(method, url))
.send_traced()
.await
.map_err(|error| Self::transport_error(&error))?;
.map_err(|error| Self::transport_error(error, cause))?;
Self::check_status(response.status(), response.headers(), Utc::now())?;
Ok(response)
}
Expand All @@ -169,9 +181,25 @@ impl OutboundClient {
Ok(url)
}

/// Classifies a request that got no response. A refused address is found in
/// the error's sources, where the resolver's error ends up.
fn transport_error(error: &reqwest::Error) -> DeliveryError {
/// Classifies a request that failed in transport, before or while its
/// response arrived, and logs why at `level` (`WARN` or `DEBUG`): the
/// classification alone becomes the delivery's `last_error`.
fn transport_error(error: reqwest::Error, level: Level) -> DeliveryError {
let failure = Self::classify(&error);
// The URL can name a person, as a provider's picture URL does.
let error = error.without_url();
let error = ErrorChain(&error);
if level == Level::WARN {
tracing::warn!(%error, %failure, "outbound request failed");
} else {
tracing::debug!(%error, %failure, "outbound request failed");
}
failure
}

/// The failure [`Self::transport_error`] reports for `error`. A refused
/// address is found in the error's sources, where the resolver's error ends up.
fn classify(error: &reqwest::Error) -> DeliveryError {
let mut source: Option<&(dyn StdError + 'static)> = Some(error);
while let Some(current) = source {
if let Some(refused) = current.downcast_ref::<ResolutionError>() {
Expand Down
5 changes: 4 additions & 1 deletion apps/auth-service/src/web/settings/emails.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
},
};
use serde::Deserialize;
use sourceorigin_common::ErrorChain;
use sourceorigin_ui::{
Audience, EmailChange, EmailRow, EmailsState, Messages, Notice, Section, Tab, Title,
};
Expand Down Expand Up @@ -46,7 +47,9 @@ impl Verification {
Self::Link { link } => link,
};
let token = Url::parse(link.trim())
.inspect_err(|error| tracing::debug!(%error, "pasted verification link rejected"))
.inspect_err(|error| {
tracing::debug!(error = %ErrorChain(error), "pasted verification link rejected");
})
.ok()
.and_then(|link| {
form_urlencoded::parse(link.fragment()?.as_bytes())
Expand Down
5 changes: 3 additions & 2 deletions apps/auth-service/src/web/settings/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::{
},
};
use serde::Deserialize;
use sourceorigin_common::ErrorChain;
use sourceorigin_ui::{
Audience, CROP_SIZE, CROP_X, CROP_Y, Messages, Notice, PICTURE_FIELD, ProfileChange,
ProfileDialog, ProfileState, Section, Tab, Who,
Expand Down Expand Up @@ -85,7 +86,7 @@ impl Profile {
return Some(ProfileEdit::Oversize);
}
Err(error) => {
tracing::debug!(%error, "picture upload rejected");
tracing::debug!(error = %ErrorChain(&*error), "picture upload rejected");
return None;
}
};
Expand All @@ -103,7 +104,7 @@ impl Profile {
return Some(ProfileEdit::Oversize);
}
Err(error) => {
tracing::debug!(%error, "picture upload rejected");
tracing::debug!(error = %ErrorChain(&*error), "picture upload rejected");
return None;
}
}
Expand Down