Compare commits

...

1 Commits

Author SHA1 Message Date
John Spray
4363132305 libs/http: include path when logging auth failures 2024-03-12 10:55:12 +00:00
2 changed files with 11 additions and 4 deletions

View File

@@ -84,6 +84,9 @@ where
info!("Handling request");
}
// Take a copy of the path for error logging
let path = request.uri().path().to_string();
// No special handling for panics here. There's a `tracing_panic_hook` from another
// module to do that globally.
let res = handler(request).await;
@@ -110,7 +113,7 @@ where
}
Ok(response)
}
Err(err) => Ok(api_error_handler(err)),
Err(err) => Ok(api_error_handler(err, Some(&path))),
}
}
.instrument(request_span)

View File

@@ -108,7 +108,7 @@ impl HttpErrorBody {
pub async fn route_error_handler(err: routerify::RouteError) -> Response<Body> {
match err.downcast::<ApiError>() {
Ok(api_error) => api_error_handler(*api_error),
Ok(api_error) => api_error_handler(*api_error, None),
Err(other_error) => {
// We expect all the request handlers to return an ApiError, so this should
// not be reached. But just in case.
@@ -121,12 +121,16 @@ pub async fn route_error_handler(err: routerify::RouteError) -> Response<Body> {
}
}
pub fn api_error_handler(api_error: ApiError) -> Response<Body> {
pub fn api_error_handler(api_error: ApiError, path: Option<&str>) -> Response<Body> {
// Print a stack trace for Internal Server errors
match api_error {
ApiError::Forbidden(_) | ApiError::Unauthorized(_) => {
warn!("Error processing HTTP request: {api_error:#}")
warn!(
"Error processing HTTP request: {api_error:#} {}{}",
path.as_ref().map(|_| "at").unwrap_or(""),
path.unwrap_or("")
)
}
ApiError::ResourceUnavailable(_) => info!("Error processing HTTP request: {api_error:#}"),
ApiError::NotFound(_) => info!("Error processing HTTP request: {api_error:#}"),