Skip to content

Commit 463bc2a

Browse files
committed
Auto merge of #2258 - jtgeibel:logs/auth-failure, r=pietroalbini
Add some error chaining to log more on auth failure cc #2252 r? @pietroalbini
2 parents 974b664 + 976fcde commit 463bc2a

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/controllers/util.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ impl<'a> UserAuthenticationExt for dyn Request + 'a {
4242
user_id: token.user_id,
4343
token_id: Some(token.id),
4444
})
45-
// Convert a NotFound (or other database error) into Unauthorized
46-
.map_err(|_| Box::new(Unauthorized) as Box<dyn AppError>)
45+
.chain_error(|| internal("invalid token"))
46+
.chain_error(|| Box::new(Unauthorized) as Box<dyn AppError>)
4747
} else {
4848
// Unable to authenticate the user
49-
Err(Box::new(Unauthorized))
49+
Err(internal("no cookie session or auth header found"))
50+
.chain_error(|| Box::new(Unauthorized) as Box<dyn AppError>)
5051
}
5152
}
5253
}

src/middleware/block_traffic.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ impl Handler for BlockTraffic {
4747
.iter()
4848
.any(|value| self.blocked_values.iter().any(|v| v == value));
4949
if has_blocked_value {
50+
let cause = format!("blocked due to contents of header {}", self.header_name);
51+
super::log_request::add_custom_metadata(req, "cause", cause);
5052
let body = format!(
5153
"We are unable to process your request at this time. \
5254
This usually means that you are in violation of our crawler \

src/middleware/require_user_agent.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ impl Handler for RequireUserAgent {
2424
let has_user_agent = request_header(req, "User-Agent") != "";
2525
let is_download = req.path().ends_with("download");
2626
if !has_user_agent && !is_download {
27+
super::log_request::add_custom_metadata(req, "cause", "no user agent");
2728
let body = format!(
2829
include_str!("no_user_agent_message.txt"),
2930
request_header(req, "X-Request-Id"),

0 commit comments

Comments
 (0)